以下是基于您的描述的简短实现。它似乎表现正确。我希望你能找到缺少的东西。
问候
ViewController.nib 由一个 UITableView 组成,其中包括一个 UIButton(调用 addApplications)
视图控制器.h
#import <UIKit/UIKit.h>
@interface ApplicationViewController : UIViewController
@property NSString* name;
@end
@interface ViewController : UITableViewController
@property ( nonatomic, retain ) NSArray* mesApplications;
- ( IBAction ) addApplications: ( id ) sender;
@end
视图控制器.m
#import "ViewController.h"
@implementation ApplicationViewController
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.mesApplications.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [ tableView dequeueReusableCellWithIdentifier: @"MyTableViewCell" ];
if ( !cell )
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyTableViewCell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
ApplicationViewController* pApp = [ self.mesApplications objectAtIndex: indexPath.row ];
[ cell.detailTextLabel setText: pApp.name ];
NSLog(@"%@", pApp);
return cell;
}
- ( IBAction ) addApplications: ( id ) sender
{
ApplicationViewController* pApp1 = [ ApplicationViewController new ];
pApp1.name = @"app1";
ApplicationViewController* pApp2 = [ ApplicationViewController new ];
pApp2.name = @"app2";
ApplicationViewController* pApp3 = [ ApplicationViewController new ];
pApp3.name = @"app3";
self.mesApplications = [ NSArray arrayWithObjects: pApp1, pApp2, pApp3, nil];
[self.tableView reloadData];
}
@end
和控制台转储
2013-03-11 13:38:17.132 kokio[10353:907] <ApplicationViewController: 0x1c535190>
2013-03-11 13:38:17.139 kokio[10353:907] <ApplicationViewController: 0x1c535260>
2013-03-11 13:38:17.142 kokio[10353:907] <ApplicationViewController: 0x1c535390>