Reputation: 319
I am developing a application in that I want to print the array value in the cell contain label place. I got the vlaues for array like names=[results valueForKey:@"name"].
I write the code for print that value in a lable in cellForRowAtIndexPath like
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSInteger row=indexPath.row;
cell = [self getCellContentView:CellIdentifier];
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
lblTemp1.text = [names objectAtIndex:row];
//lblTemp2.text = [names objectAtIndex:row];
return cell;
}
but ,when the application got the error at lblTemp1.text = [names objectAtIndex:row]
like Program received signal: “EXC_BAD_ACCESS”.So please tell me how to solve this problem.
Upvotes: 0
Views: 507
Reputation: 25692
seems to be new bee. please check out for step by step tutorial
http://adeem.me/blog/2009/05/19/iphone-programming-tutorial-part-1-uitableview-using-nsarray/
Upvotes: 0
Reputation: 51374
It seems you've missed to retain the array names. Try,
names = [[results valueForKey:@"name"] retain];
You could consider using declared properties to overcome the overhead of retaining and releasing the objects.
Upvotes: 1