Muhammad Mujahid
Muhammad Mujahid

Reputation: 25

cell.textlabel.text not working properly

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellIdentifire";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSString *makingString_fromArray = [appDel.Rhymes_Array objectAtIndex:indexPath.row];
    NSArray *datatwoParts_Array = [makingString_fromArray componentsSeparatedByString:@"@"];

    cell.textLabel.text = [datatwoParts_Array objectAtIndex:0];
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textAlignment = NSTextAlignmentLeft;

    // Assign our own background image for the cell
    UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
    UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
    cellBackgroundView.image = background;
    cell.backgroundView = cellBackgroundView;
    return cell;
}

In my tableview, only first cell data show, others empty cell.i also NSLog the the array , data is there on each index but not show in the cell. Only first cell data show.Thanks for help

Upvotes: 0

Views: 2779

Answers (6)

Lait kumar
Lait kumar

Reputation: 112

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
    return [datatwoParts_Array count];
}



 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath

 {

     cell.textLabel.text = [datatwoParts_Array objectAtIndex:indexPath.row];

     NSLog(@" check the array value ======== %@",[datatwoParts_Array objectAtIndex:indexPath.row]);   
 } 

Upvotes: 0

brokenrhino
brokenrhino

Reputation: 160

This should work with the 6.1 beta.

cell?.textLabel?.text = [datatwoParts_Array objectAtIndex:0]

Upvotes: 0

kagmanoj
kagmanoj

Reputation: 5368

Same problem i found in my project and this table method i founded try to this

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor clearColor];
    cell.layer.backgroundColor = (__bridge CGColorRef)([UIColor clearColor]);//optional
    cell.backgroundView = nil;
}

Upvotes: 0

Muhammad Mujahid
Muhammad Mujahid

Reputation: 25

Thanks all of You. problem is that i am getting \r\n in Stringpath, thats why text other than first cell not showing. i used NSCharacterset to remove unused characters from string.

Upvotes: 0

KingofBliss
KingofBliss

Reputation: 15115

Make sure you returning the count as,

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [datatwoParts_Array count];
}

Also change the following line of code

cell.textLabel.text = [datatwoParts_Array objectAtIndex:0];

as.

 cell.textLabel.text = [datatwoParts_Array objectAtIndex:indexPath.row];

EDIT:

Your code is little bit confusion, What you are trying to achieve here?

NSString *makingString_fromArray = [appDel.Rhymes_Array objectAtIndex:indexPath.row];
NSArray *datatwoParts_Array = [makingString_fromArray componentsSeparatedByString:@"@"];

Also please share your tableView:numberOfRowsInSection: method

Upvotes: 3

codercat
codercat

Reputation: 23271

check your

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        if([datatwoParts_Array count]!=0)
    return [datatwoParts_Array count];


 return 0;
}

Upvotes: 1

Related Questions