-1
不明白爲什麼的cellForRowAtIndexPath不會被調用,即使numberOfRowsInSection被稱爲 我把這個視圖控制器與的cellForRowAtIndexPath不會觸發
ServerDataController * DataController類= [[ServerDataController頁頭] initWithNibName:@ 「ServerDataController」 捆綁:零];
[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;
}
有什麼建議?
我在解析XML文件時添加了項目,並沒有包含那麼大的代碼。陣列不是空的肯定。 cellForRowAtIndexPath無論如何應該觸發 – Oleg 2012-04-24 20:16:56
好吧,一個遠射,但你會驚訝愚蠢的東西,我寫了我的代碼時,東西看起來:)爲什麼你的控制器UIViewController而不是UITableViewController?我認爲你應該實現UITableViewDelegate,如果你是一個普通的UIViewController而不是UITableViewController – verhage 2012-04-24 20:20:50