下面是tablecell的設定 code
這是運行的效果,不用代碼添加的cell, 附上代碼: #pragma mark - #pragma mark Table View Data Source Methods //返回組數 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } //返回每組的行數 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { int count; if (section == 0) { count = 1; } if (section == 1) { count = 4; } return count; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ NSString *title = nil; if (section == 0) { title = @"登錄"; } if (section == 1) { title = @"綁定"; } return title; } //設定錶行不可選中 -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{ return nil; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; //設置每行標題 UITableViewCell *cell = [[UITableViewCell alloc]init]; if (section == 0) { cell = cell0; } if (section == 1 && row == 0) { cell = cell1; } if (section == 1 && row == 1) { cell = cell2; } if (section ==1 && row == 2) { cell = cell3; } if (section == 1 && row ==3) { cell = cell4; } // cell.textLabel.text = [nameSection objectAtIndex:row]; return cell; }
感受這樣作比較有靈活性減小代碼使用量,比較適合像我這樣的菜鳥 - -!it
第一次寫這個 - -多多包涵@。@io