2012-09-03 3 views

답변

1

설정 UISwitch 버튼 :

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString* cellId = @"cellId"; 
    UITableViewCell* cellView = [self.tableView dequeueReusableCellWithIdentifier:cellId]; 
    if(!cellView) { 
     cellView = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; 
     UISwitch* switchBtn = [[UISwitch alloc] init]; 
     [switchBtn addTarget:self action:@selector(onSwitchBtn:) forControlEvents:UIControlEventValueChanged]; 
     cellView.accessoryView = switchBtn; 
    } 
    return cellView; 
} 
+0

대단히 감사합니다. – Chakri

+0

이 코드는 완벽합니다! 고마워요 @onegray – Kernelzero

0

스토리 보드 또는 xibs를 사용하고 있습니까? 스토리 보드에서 UISwith를 셀로 드래그 할 수 있다고 생각합니다.

xib를 사용하는 경우 사용자 지정 셀이 필요합니다. 다음, 인터페이스 빌더는있는 tableview 외부에서 XIB에있는 UITableViewCell을 드래그있는 UITableViewCell 내부의 UISwitch를 드래그하고있는 UITableViewCell에 함께 IBOutlet을 넣어

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
if (indexPath.row == rowWhereYouWantTheCellWithTheUISwitch){ 
    return UITableViewCellWithTheSwitchName; 
} 
} 

rowWhereYouWantTheCellWithTheUISwitch를 사용하면 사용자 정의 세포를 원하는 세포의 수입니다. UITableViewCellWithTheSwitchName은 생성 한 IBOutlet의 이름입니다. UITableViewCell을위한 액세서리로

+0

예. 알았습니다. 프로그래밍으로 내 테이블을 만들었습니다 .ThanQ ... – Chakri

1

당신은 당신이 MonoTouch를 사용하고 있기 때문에, 당신은 MonoTouch.Dialog를 보라 (해야하고, C# 기존 (목표 - C) 답변을 번역 할 수 있지만, 샘플 응용 프로그램입니다.)

UITableView 상단에 훨씬 더 쉬운 API를 제공하며 여전히 대부분의 일반적인 사용/시나리오가 필요한 테이블을 포함합니다.

세포에서 사용되는 UISwitch을 보려면 스크린 샷 (이전 링크에서)을 참조하십시오.

+0

나는이 대답을 가지고 .. ThanQ .. – Chakri

관련 문제