cellForRowAtIndexPath不会触发

时间:2012-04-24 20:02:30

标签: objective-c xcode cocoa-touch

无法理解为什么从不调用cellForRowAtIndexPath,即使调用了numberOfRowsInSection 我将此ViewController称为

ServerDataController * dataController = [[ServerDataController alloc] initWithNibName:@“ServerDataController”bundle:nil];

[self presentModalViewController:dataController animated:YES];

这是我的代码: 头文件:

#import <UIKit/UIKit.h>

@interface ServerDataController : UIViewController <NSXMLParserDelegate, NSURLConnectionDelegate, UITableViewDataSource>
{
...
    NSMutableArray *items;
    UITableView *docsTableView;

}
@property (retain, nonatomic) IBOutlet UITableView *docsTableView;

@property (nonatomic, readonly) NSMutableArray *items;

@end

实施档案:

#import "ServerDataController.h"

@implementation ServerDataController
@synthesize docsTableView;
@synthesize items;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (id)init
{
    self = [super init];

    if (self)
    {

    }

    return self;
}


- (void)dealloc {

    [items release];
    [docsTableView release];
    [super dealloc];
}

- (void)viewDidAppear:(BOOL)animated
{
    [self fetchEntries];
    animated = YES;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    if (self) {
        items = [[NSMutableArray alloc] init];
    }
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[self items] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    NSString *cellTitle = [[[[items objectAtIndex:indexPath.row] docUrl] lastPathComponent] stringByDeletingPathExtension];

    cell.textLabel.text = cellTitle;
    return cell;
}

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

我没有看到你在数组中添加项目的位置,只有viewDidLoad中的init,我认为它是空的,所以这就是永远不会调用该函数的原因。根本没有任何项目可以显示。

相关问题