titleForHeaderInSection를 설정하는 방법 :수동
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [[documentPaths lastObject] stringByAppendingPathComponent:@"data.plist"];
NSMutableDictionary *resultDic = [[NSMutableDictionary alloc] init];
NSMutableArray *resultArray = [[NSMutableArray alloc] init];
NSDictionary *myDict = [NSDictionary dictionaryWithContentsOfFile:path];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"purpleKey"])
{
NSArray *purple = [myDict objectForKey:@"Purple"];
[resultArray addObject:@"Purple"];
[resultDic setValue:purple forKey:@"Purple"];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"orangeKey"])
{
NSArray *orange = [myDict objectForKey:@"Orange"];
[resultArray addObject:@"Orange"];
[resultDic setValue:orange forKey:@"Orange"];
}
self.tableData = resultDic;
self.sectionsTitle = resultArray;
}
titleForHeaderInSection
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [sectionsTitle objectAtIndex:section];
}
내 PLIST 구조
내 질문은 : 어떻게해야합니까? plist 파일에서 이름을 변경하지 않고 자주색 머리글과 오렌지 머리글에 대한 제목을 수동으로 설정 했습니까? 이 같은 : 퍼플 = 범주 1, 오렌지 = 카테고리 2
당신이 상수 문자열 오렌지와 채우기하는 코드 섹션 헤더 resultsArray
에서 오는,의 모습에서 편집
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return sectionsTitle.count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [sectionsTitle objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int num = [[tableData objectForKey:[sectionsTitle objectAtIndex:section]] count];
if (num > 3) {
num = 3;
}
return num;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *dict = [[tableData objectForKey:[sectionsTitle objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.numberOfLines = 1;
cell.textLabel.font = [UIFont systemFontOfSize:11];
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", [dict objectForKey:@"Name"], [dict objectForKey:@"Address"]];
if ([dict objectForKey:@"Address"] == (NULL)) {
//do nothing
}
return cell;
}
앱이 실행 중일 때 의미합니까, 당신은 제목을 변경할 수 있습니다, 또는 당신은 단지 다른 값으로 개발하는 동안이를 변경하려면 ? – jrturton
다른 값으로 개발 중 –