1

I working on grouped table view based work in that in that i want to convert the value of NSarray into integer for specifing to section value of numberOfRowsInSection but it throws expection on putting following code.

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

 int sec;
 if (section == 0){ sec=6; }
 else if(section == 1){ sec=6; }
 else if(section == 2){ 
 sec=[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"];
 }
 return sec;
}

Anybody help to recify it advance thanks for your suggestion

Regards, sathish

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
sathish kumar
  • 1,061
  • 6
  • 16
  • 31

2 Answers2

3

NSArray and NSDictionary can only hold Objective-C objects. An int is not an object. It is likely the number is wrapped as an NSNumber. To convert an NSNumber back to an int, call -intValue:

 sec = [[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"] intValue];
 //                                                                 ^^^^^^^^

Of course, make sure rsvn_detail is really an NSArray of NSDictionary. Without -intValue won't cause exceptions, only compiler warning/error will be raised.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
0

What is the exception? Seems that

[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"];
is causing the problem.
taskinoor
  • 45,586
  • 12
  • 116
  • 142