开发者

Problems with UITableViewDelegate

I have a UITableView with multiple sections. I have an NSMutableArray as the DataSource (floorArray). When I reload the tableview data I get [FloorGroup count]: unrecognized selector sent to instance 0x5c18fc0. My ViewController implements UITableViewDelegate and UITableViewDataSource. I can't see anywhere I'm calling count on a FloorGroup object.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [floorArray count];

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    FloorGroup *group = [floorArray objectAtIndex:section];
    return group.floorName;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    FloorGroup *group = [floorArray objectAtIndex:section];
    NSMutableArray *areasOnFloor = group.areas;
    NSUInteger count = [areasOnFloor count];
    return count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FloorGroup *group = [floorArray objectAtIndex:[indexP开发者_开发问答ath section]];

    static NSString *identity = @"MainCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identity];

    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 0.0) reuseIdentifier:identity] autorelease];
    }
    cell.text = [group.areas objectAtIndex:indexPath.row];

    return cell;
}

My class definitions are:

@interface FloorGroup : NSObject {
    NSString *floorName;
    NSMutableArray *areas;
}

@interface FloorArea : NSObject {
    NSString *floor;
    NSString *description;
    NSDecimalNumber *area;
    NSDecimalNumber *price;
}

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

The exact error is:

2011-08-05 10:54:58.692 com.Lime49.myApp[1987:207] -[FloorGroup count]: unrecognized selector sent to instance 0x5d93c90
2011-08-05 10:54:58.694 com.Lime49.myApp[1987:207] NSInvalidArgumentException
2011-08-05 10:55:02.321 com.Lime49.myApp[1987:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FloorGroup count]: unrecognized selector sent to instance 0x5d93c90'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x0139f5a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x014f3313 objc_exception_throw + 44
    2   CoreFoundation                      0x013a10bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x01310966 ___forwarding___ + 966
    4   CoreFoundation                      0x01310522 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x006492b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834
    6   UIKit                               0x00646d88 -[UITableViewRowData numberOfRows] + 108
    7   UIKit                               0x004fa677 -[UITableView noteNumberOfRowsChanged] + 132
    8   UIKit                               0x00507708 -[UITableView reloadData] + 773
    9   Foundation                          0x0020b94e __NSThreadPerformPerform + 251
    10  CoreFoundation                      0x013808ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    11  CoreFoundation                      0x012de88b __CFRunLoopDoSources0 + 571
    12  CoreFoundation                      0x012ddd86 __CFRunLoopRun + 470
    13  CoreFoundation                      0x012dd840 CFRunLoopRunSpecific + 208
    14  CoreFoundation                      0x012dd761 CFRunLoopRunInMode + 97
    15  GraphicsServices                    0x01b3c1c4 GSEventRunModal + 217
    16  GraphicsServices                    0x01b3c289 GSEventRun + 115
    17  UIKit                               0x0049ac93 UIApplicationMain + 1160
    18  com.Lime49.myApp                0x00002256 main + 84
    19  com.Lime49.myApp                0x000021f9 start + 53
)
terminate called after throwing an instance of 'NSException'


your error look like your object having pointer of class FloorGroup rather than floorArray.

Either your array is already released and its memory occupied by FloorGroup object. Debug wether your floorArray having object or not.


Where do you initialize 'floorArray'?

Try do it in a init and not in the viewDidLoad (view tries to load the array with is initialized after the view tries to load.. get it?)


Chek your floorArray may be it has released.


Pain of a problem. I had around 20 lines of code in my DAL to parse an XML element tree to Objective-C objects. I was creating FloorGroups, adding them to a dictionary, then looping at the end and casting the values to NSMutableDictionary. I don't really understand why the compiler even let me do this or why it ran, but I just needed to skip the final loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜