저는 여전히 objective-c에 대해 매우 새롭기 때문에 답을 찾아 보았습니다. 나는 내가 발견 한 것을 성공적으로 구현할 수 없었다. 내가 찾은 오픈 소스 슬라이딩 메뉴를 사용하고 있으며, 사용하는 코드에 맞는 것을 찾지 못했습니다. (나는 그것에 대한 링크를 게시 하겠지만, 내가 그것을 발견 한 곳을 기억할 수 없다.)헤더가있는 섹션을 UITableViewController (iOS)에 추가하려고 시도했습니다.
편집 : 섹션을 추가했습니다. 이제 두 번째 섹션의 첫 번째 셀이 첫 번째 섹션에만 표시되도록해야합니다. http://i.imgur.com/gSIRNJ3.png
아래 코드를 업데이트했습니다. 여기에 내가하려고하는 것에 대한 참조가 있습니다. 지금, 전지 (1) 두 섹션 1과 섹션에 표시 2.
1 : (어떤 헤더 없음) - 셀 (1) : "검색 명사"
2 : "명사 활용"
- 세포 2 : "일반 명사"
- 셀 3 : "불규칙 명사"
- 셀 4 : 당신이 2를 반환 numberOfSectionsInTableView:
의 위양 있어야 "셀 수없는 명사"또한
#import "BaseTableViewController.h"
#import "KYSlideMenuViewController.h"
@interface BaseTableViewController() {
int _currentCtrNum;
}
@end
@implementation BaseTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// 最初に表示するビューを設定する
_currentCtrNum = -1;
NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0];
[self tableView:self.tableView didSelectRowAtIndexPath:path];
}
#pragma mark -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2 ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section == 0)
return 1;
else
return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section==0)
return 0;
else
return 25;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0)
return @"";
else
return @"reference";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"名詞検索";
break;
case 1:
cell.textLabel.text = @"Side B";
break;
case 2:
cell.textLabel.text = @"Side C";
break;
case 3:
cell.textLabel.text = @"Side D";
default:
break;
}
cell.backgroundColor = [UIColor grayColor];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
for (int i = 0 ; i < [tableView numberOfRowsInSection:0] ; i++) {
NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:0];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
if (i == indexPath.row) {
cell.textLabel.textColor = [UIColor whiteColor];
} else {
cell.textLabel.textColor = [UIColor blackColor];
}
}
// 現在のビューコントローラなら表示するだけ
if (_currentCtrNum == indexPath.row) {
[(KYSlideMenuViewController *)self.parentViewController slideChildTo:KYS_CLOSE];
return;
}
_currentCtrNum = (int)indexPath.row;
// 新しいビューコントローラを生成してコンテナのビューコントローラを入れ替え
UIViewController *toCtr;
switch (indexPath.row) {
case 0: // noun search
toCtr = [[self storyboard] instantiateViewControllerWithIdentifier:@"itemTableView"];
break;
case 1: // navigationあり
toCtr = [[self storyboard] instantiateViewControllerWithIdentifier:@"mainView"];
break;
case 2: // navigationなし
toCtr = [[self storyboard] instantiateViewControllerWithIdentifier:@"subView"];
break;
case 3: // navigationあり
toCtr = [[self storyboard] instantiateViewControllerWithIdentifier:@"srdView"];
break;
default:
return;
}
[(KYSlideMenuViewController *)self.parentViewController changeTo:toCtr];
}
@end
이 메소드는'numberOfSectionsInTableView :'입니다. – rmaddy
고마워요! 그것은 많은 도움이됩니다. 이제, 두 번째 섹션에서 첫 번째 셀을 표시하지 않는 방법을 알아야합니다. http://i.imgur.com/gSIRNJ3.png – Jacob
당신은'tableView : cellForRowAtIndexPath :'의'indexPath.section'과'indexPath.row'의 값에 기초한 논리가 필요합니다. –