UITableViewCell
에는 셀에 레이블이 있고 UITextField
이 미리 채워져 있습니다. 레이블이 "map"인 셀이 있고 그 셀에 단추를 추가하려면 어떻게해야합니까?
시도했지만이 작동하지 않습니다.
여기에 코드입니다 :UITableViewCell에 단추를 추가하는 방법
UITAbleViewCell
에 버튼을 추가 할 수있는 몇 가지 방법이있다
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"rateSheetCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (indexPath.row == 0)
{
((UILabel*)[cell viewWithTag:100]).text = @"Title";
((UITextField*)[cell viewWithTag:101]).placeholder = @"Title";
((UITextField*)[cell viewWithTag:101]).text = arrayResourceColumns[indexPath.section][indexPath.row][@"resource_title"];
((UITextField*)[cell viewWithTag:101]).keyboardType = UIKeyboardTypeDefault;
}
else
{
if([arrayResourceColumns[indexPath.section][indexPath.row][@"label"] isEqualToString:@"OT ($)"]){
NSInteger desiredLabel = (NSInteger)(arrayResourceColumns[indexPath.section][indexPath.row][@"label"]);
//NSString *desiredLabel = arrayResourceColumns[indexPath.section][indexPath.row][@"label"];
NSLog(@"Label is>>>>--------%ld", (long)desiredLabel);
if (indexPath.row == desiredLabel) {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setFrame:CGRectMake(0, 0, 50, 50)];
}
}
((UILabel*)[cell viewWithTag:100]).text = arrayResourceColumns[indexPath.section][indexPath.row][@"label"];
((UITextField*)[cell viewWithTag:101]).placeholder = ((UILabel*)[cell viewWithTag:100]).text;
((UITextField*)[cell viewWithTag:101]).text = arrayResourceColumns[indexPath.section][indexPath.row][@"attribute_value"];
if (indexPath.row == [arrayResourceColumns[indexPath.section] count] - 1)
{
((UITextField*)[cell viewWithTag:101]).enabled = NO;
}
}
}
당신이 셀의 파단에 액세스 할 수 태그 (100) 및 (101)을 사용하는 것과
UITableViewCell
을 사용자 정의하는 방법을 튜토리얼. 그러나 당신은 그들을 세포에 어디에 추가 했습니까? 그것들은'cell == nil'의 경우 btw에 추가되어야합니다. –@Khanh 태그는 textlabel 및 textfield이고 textlabel이고 textfield는 스토리 보드의 uitableviewcell 프로토 타입에 추가되었습니다 – Ammad
@ user1699419 자신 만의 사용자 정의 테이블보기 셀을 사용할 수 있습니다. 이 내부 UIButton, UILabel 및 UITextField 등 하위 뷰를 추가 할 수 있습니다 ... Hv 솔루션있어? –