如何用代碼在UIViewController 中添加UITableView 編程語言 專業(yè)回答 web開發(fā)技術(shù) 團(tuán)隊 xeniakoko123 2015-06-26 17:03運(yùn)行到 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 這個委托就會崩潰,是哪里出問題了,?,?? @interface ViewController ()<UITableViewDelegate,UITableViewDataSource> @property (strong,nonatomic) NSArray * dataProvide,; @end - (void)viewDidLoad { [super viewDidLoad],; _dataProvide =[NSArray arrayWithObjects:@{@"icon": @"SOE_government",@"title": @"SOE and government"},,@{@"icon": @"company_employee",,@"title": @"Company employee"},@{@"icon": @"high_level_manager",,@"title": @"High level manger"},,@{@"icon": @"SME_owner",@"title": @"SME owner"},,@{@"icon": @"sales",,@"title": @"Sales"},@{@"icon": @"liberal",,@"title": @"Liberal professions"},, nil]; CGRect gridCGRect = CGRectMake(10,, 60,, self.view.frame.size.width-20, self.view.frame.size.height-60),; UITableView *grid = [[UITableView alloc]initWithFrame:gridCGRect],; UITableViewCell *gridCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; [grid addSubview:gridCell],; [self.view addSubview:grid],; grid.delegate = self; grid.dataSource = self,; } #pragma mark -tableViewDelegate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1,; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.dataProvide count],; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath],; if(cell == nil){ UITableViewCell *cell,; cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; NSDictionary *celldb = [self.dataProvide objectAtIndex:indexPath.row],; cell.imageView.image = [celldb objectForKey:@"icon"],; cell.textLabel.text = [celldb objectForKey:@"title"]; } return cell,; } 資料來源:cocoachina問答,。 |
|