In fact converting the value to be returned to the count of an NSArray, as opposed to the count an NSMutableArray fixes the issue. Why? I am not sure why an NSArray's count value is valid but not the NSMutableArray's. Anyone?
NSInteger value not valid when passing in a variable, for custom table view class delegate method
-
12-12-2021 - |
Question
I'm testing a custom table view style class:
It produces a horizontal table view.
One of the delegate methods equivalent to tableView:numberOfRowsInSection:
is:
- (NSInteger)numberOfColumnsForTableView:(HorizontalTableView *)tableView.
If I give this a number (ex: return 10;
) it is happy and it give me the number "cells" that I want. But if I feed it a value of someArray.count
or an int
or NSInteger
variable, the table view just comes out blank, delivering no cells.
I think that the method in the custom table view class that receives the NSInteger
value is this:
- (NSUInteger)numberOfPages {
NSInteger numPages = 0;
if (_delegate)
numPages = [_delegate numberOfColumnsForTableView:self];
return numPages;
}
Do I need to cast the result of someArray.count
to an NSInteger
?
Solution 4
OTHER TIPS
Here you get the value from array means your array not nil so just debug and check the if condition that its come in that condition or not and what you get from NSLog
- (NSUInteger)numberOfPages {
NSInteger numPages = 0;
if (_delegate){
numPages = [_delegate numberOfColumnsForTableView:self];
NSLog(@"Total record %d",numPages);//what you get here?
}
return numPages;
}
numPages = [_delegate numberOfColumnsForTableView:self];
//self requires an object of type HorizontalTableView
NSMutableArray is editable, where as NSArray is read-only.
NSMutableArray
is a subclass of NSArray
and responds to messages such as addObject
, removeObject
and so forth; i.e. it is mutable, like the name says. Instead, NSArray
is immutable, i.e. you can't add/remove objects.