XCode6에 앱을 쓰고 있습니다. 현재 나는 "SelectionTableViewController.h"및 "SelectionTableViewController.m"을 가지고 있으므로 선택시 체크 표시를 추가/제거 할 수 있습니다. 또한 이전 테이블 뷰 컨트롤러의 정적 셀에 의해 트리거되는 스토리 보드에 테이블 뷰 컨트롤러 segue가 있습니다. 나는 스토리 보드에서 트리거를 설정 했으므로 "segue를 준비하라"라는 코드를 작성하지 않았습니다. 나는 셀이 기본적으로 선택해야 할, 그래서 나는 다음과 같은 짓을 :내 테이블보기 컨트롤러를 스토리 보드에 내 코드에 연결할 수 없습니다.
- 뷰 컨트롤러를 변경하는 "SelectionTableViewController"
- 내 스토리 보드 프로토 타입 셀의 식별자를 설정하는 "SelectionCell"
- 는 체크 표시 오렌지와 액세서리로 셀의 배경 색상을 변경 아래
내 SelectionTableViewController.m입니다 :
@implementation SelectionTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class]
forCellReuseIdentifier:@"SelectionCell"];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO];
self.navigationItem.title = @"Select";
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [[[MyStore sharedStore] allCategories] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSString *category = [[[MyStore sharedStore] allCategories] objectAtIndex:section];
return [[[MyStore sharedStore] allNamesForCategory: category] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath*)indexPath
{
UITableViewCell *cell=[tableViewdequeueReusableCellWithIdentifier:@"SelectionCell"forIndexPath:indexPath];
// Configure the cell...
NSString *category = [[[MyStore sharedStore] allCategories] objectAtIndex:indexPath.section];
NSArray *items = [[MyStore sharedStore] allNamesForCategory: category];
cell.textLabel.text = [items objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[[MyStore sharedStore] allCategories] objectAtIndex:section];
}
@end
내 프로그램이 시뮬레이터에서 실행되고 셀에 나열된 항목이 올바른 것입니다. 그러나 셀을 선택하기 전에 셀에 기본 체크 표시가 없습니다. 세포도 오렌지색이 아닙니다. 나는 기본 체크 마크와 배경색을 코드에 쉽게 설정할 수 있다는 것을 알고 있지만 인터페이스 빌더에서이 작업을 수행하는 방법을 알고 싶다. 프로그램을 설정할 때 UI를 많이 다룰 것이기 때문이다.
누군가가 내가 iOS 프로그래밍을 처음 접했을 때 나를 도울 수 있기를 바랍니다. 스토리 보드를 사용한 적이 처음입니다. 감사!
사실 나는 그것을 직접 알아 냈습니다. 감사! –