2
내 프로그램에서 동적으로 UITableView를 만들었습니다. .H 파일에서수동으로 UITableView 호출하는 방법
나는이 작성한 : 내가 작성한
aTableView=[[UITableView alloc] initWithFrame:[[UIScreen mainScreen]applicationFrame]
style:UITableViewStyleGrouped];
aTableView.delegate=self;
aTableView.datasource=self;
aTableView.autoresizeSubviews=YES;
self.view=aTableView
외부 didload 방법 didload 방법에 :하는 .m 파일에서
UITableView *aTableView
을 나는이 작성한 이 :
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [a count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *[email protected]"Cell";
static NSInteger StateTag = 1;
static NSInteger CapitalTag = 2;
static NSInteger StateTag1 = 3;
static NSInteger StateTag2 = 4;
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell=[[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease];
CGRect frame;
frame.origin.x = 10;
frame.origin.y = 5;
frame.size.height = 35;
frame.size.width = 170;
UILabel *capitalLabel = [[UILabel alloc] initWithFrame:frame];
capitalLabel.tag = CapitalTag;
[cell.contentView addSubview:capitalLabel];
frame.origin.x += 175;
UILabel *stateLabel = [[UILabel alloc] initWithFrame:frame];
stateLabel.tag = StateTag;
[cell.contentView addSubview:stateLabel];
frame.origin.x += 180;
UILabel *stateLabel1 = [[UILabel alloc] initWithFrame:frame];
stateLabel1.tag = StateTag1;
[cell.contentView addSubview:stateLabel1];
frame.origin.x += 190;
UILabel *stateLabel2 = [[UILabel alloc] initWithFrame:frame];
stateLabel2.tag = StateTag2;
[cell.contentView addSubview:stateLabel2];
}
UILabel *capitalLabel = (UILabel *) [cell.contentView viewWithTag:CapitalTag];
UILabel *stateLabel = (UILabel *) [cell.contentView viewWithTag:StateTag];
UILabel *stateLabel1 = (UILabel *) [cell.contentView viewWithTag:StateTag1];
UILabel *stateLabel2 = (UILabel *) [cell.contentView viewWithTag:StateTag2];
capitalLabel.text=[a objectAtIndex:indexPath.row];
stateLabel.text = [b objectAtIndex:indexPath.row];
stateLabel1.text = [c objectAtIndex:indexPath.row];
stateLabel2.text = [d objectAtIndex:indexPath.row];
return cell;
}
이 테이블은 자동으로 호출되므로이 tableview를 자동으로 호출하고 싶지 않습니다. 어.
이 tableview를 프로그래밍 방식으로 호출하려고합니다.
어떻게해야합니까 ??
위의 코드는 꽤 프로그래밍 적입니다. 원하는 것을 명확히 할 수 있습니까? – bryanmac
프로그램 적으로 테이블을 호출하려고합니다. –
위임자와 데이터 소스를 설정할 때 프로그래밍 방식으로 호출합니다. 그런 다음 다시 전화를 걸면 프로그래밍 방식으로 해당 콜백에 응답하고 있습니다. 콜백 패턴을 원하지 않는다고 말하는 대신 행을 설정하여 테이블을 채우고 싶습니까? – bryanmac