<分区>
<分区>
我目前有一个标签栏应用程序正在开发中,但遇到了一些障碍。 TableView 中未填充任何数据,当我尝试使用 NSMutable 数组中的记录加载我的 TableViewController 时。
RootViewController 方法 - 即 TableViewController
- (id)init
{
//Call the superclass's designated initalizer
self = [super initWithNibName:nil bundle:nil];
if (self){
//Populate NSMutalableArry with all pub objects
for(int i=0; i<10; i++){
[[PubStore defaultStore] createPub];
//j = [[[[PubStore defaultStore] allPubs] objectAtIndex:i] getPubName];
}
//Get the tab bar item
UITabBarItem *tbi = [self tabBarItem];
//Give it a label
[tbi setTitle:@"Pubs"];
//Create a UIImage from a file
UIImage *i = [UIImage imageNamed:@"88-beermug.png"];
//Put Image on the tab bar item
[tbi setImage:i];
}
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[[PubStore defaultStore] allPubs] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Create an instnce of UITableViewCell, with default appearance
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"] autorelease];
//Set the text on the cell with the description of the possession
//that is at the nth index of the possessions, where n =row this cell
//will appear in on the tableview
Pub *p = [[[PubStore defaultStore] allPubs] objectAtIndex:[indexPath row]];
NSLog(@"Display Pub Name: %@", [p getPubName]);
[[cell textLabel] setText: [p getPubName]];
return cell;
}
酒吧商店方法
- (id)init
{
if (defaultStore) {
//Return the old Default Store
return defaultStore;
}
self = [super init];
if(self){
allPubs = [[NSMutableArray alloc] init];
}
return self;
}
- (NSArray *)allPubs
{
return allPubs;
}
- (Pub *)createPub
{
//* random possessions does not exist in my Pub Class
Pub *p = [Pub randomPub];
NSLog(@"New Pub: %@", p);
[allPubs addObject:p];
return p;
}
如果您能提供给我任何帮助,我将不胜感激,我正在学习 objective-c ,这是我需要克服的一个障碍。
最佳答案
在您的 RootViewController.init() 方法中,您需要这样的东西:
self.table.dataSource = self;
self.table.delegate = self;
假设 table
是您的 UITableView
的名称。
关于iphone - UITableViewController 不使用 NSMutableArray 填充 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9137365/
相关文章:
iphone - 单击 DetailDesclosure 按钮时 MKAnnotationView 推送到 View Controller
Ios 7 自定义 UINavigationController 动画因目标 Controller 中的 mapView 而失败
ios - removeObserver 使我的应用程序崩溃,即使它似乎与 addObserver 保持平衡
ios - 关于 MKMapView -regionThatFits :? 的 Apple 文档不正确
iphone - 如何从 UIDatePicker 获取值?
objective-c - 表单模态视图 Controller 不会在 iOS6 中关闭