views:

40

answers:

2

Hi friend,

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

A: 

What is the exception? Seems that

[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"];
is causing the problem.

taskinoor
+1  A: 

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
ok man thanks it worked
sathish kumar
You should flag this as the answer Satish...
NinjaCat