androniennn
androniennn

Reputation: 3137

numberofRowsinSection can it return the VALUES of NSMutableArray?

Is that possible to return as number of rows in section the value(and not the count) of an NSMutableArray

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"number of rows in section: %@",[arrayofNombre objectAtIndex:section]);//it prints the right value
    return [arrayofNombre objectAtIndex:section];
}

The application just crashes, and when I put a constant value (return 2 for example), the application runs but it gives not the expected result. I'm surely missing something. Thank you for helping.

Upvotes: 0

Views: 297

Answers (3)

Felix
Felix

Reputation: 35384

If your array holds instances of NSNumber you need to convert the object to NSInteger:

return [[arrayofNombre objectAtIndex:section] integerValue];

Upvotes: 1

Matt
Matt

Reputation: 2411

It seems that you're returning an NSNumber, while the method is expecting an NSInteger. You should convert the NSNumber as follows.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"number of rows in section: %@",[arrayofNombre objectAtIndex:section]);//it prints the right value
    return [[arrayofNombre objectAtIndex:section] intValue];
}

Upvotes: 5

Mark McCorkle
Mark McCorkle

Reputation: 9414

No. You are returning an NSInteger. You need to explicitly declare a property to hold the value if you choose.

Upvotes: 1

Related Questions