在視圖控制器
.H
@property (strong, nonatomic) IBOutlet UITableView *tableViewData;
.M
#import "ViewController.h"
#import "CustomCell.h"
@interface ViewController()
{
NSDictionary *dictComments;
NSArray *arrayUser;
NSArray *arrayContents;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
dictComments = [[NSDictionary alloc]initWithObjectsAndKeys:@"Jin",@"User",@"iOS Developer",@"Content", nil];
arrayUser = [[NSArray alloc]initWithObjects:[dictComments objectForKey:@"User"], nil];
arrayContents = [[NSArray alloc]initWithObjects:[dictComments objectForKey:@"Content"], nil];
}
//UITableViewDataSource Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return arrayUser.count;
//OR
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"CustomCell";
CustomCell *cell=(CustomCell*)[tableView dequeueReusableCellWithIdentifier:customTableIdentifier];
if (cell==nil)
{
NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
cell=[nibs objectAtIndex:0];
}
cell.labelUserName.text = [NSString stringWithFormat:@"%@",[arrayUser objectAtIndex:indexPath.row]];
cell.labelTextContent.text = [NSString stringWithFormat:@"%@",[arrayContents objectAtIndex:indexPath.row]];
//OR
cell.labelUserName.text = [NSString stringWithFormat:@"%@",[dictComments objectForKey:@"User"]];
cell.labelTextContent.text = [NSString stringWithFormat:@"%@",[dictComments objectForKey:@"Content"]];
return cell;
}
想不通是什麼的話你post.So的問題,最好是張貼一些代碼。 – Leo
張貼代碼.. –
當你說模擬器被凍結時,程序是否崩潰?你能發佈崩潰日誌嗎? – TheAppMentor