2012-12-10 4 views
0

! [이미지 설명을 여기에 입력하십시오] [1] 버튼을 누른 부분을 표시하고 싶습니다. 현재 섹션 시간에 시간을 표시하고 싶습니다. 한 셀이 표시됩니다 섹션이 표시됩니다. 버튼이 동시에 눌린 날짜, 섹션 제목은 2를 원하지 않습니다. 먼저 정적 TableView를 만들었습니다. 여러 사이트를 읽는 동안이 목적, 동적 TableView를 만들려고했습니다. 코드가 주석 처리되었습니다. 코드 샘플을 알려주십시오.동적 테이블보기를 만드는 방법

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 2; 
    //return [array count]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    NSString *title = @"section"; 
    return title; 

    //return [array objectAtIndex:section]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 1; 
} 


- (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]; 
    } 

    cell.textLabel.text = [NSString stringWithFormat:@"%@ %i", @"row", indexPath.row]; 
    return cell; 
} 

-(void)addButton 
{ 
    NSDate *date = [NSDate date]; 
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
    [formatter setDateStyle:NSDateFormatterMediumStyle]; 

    NSString *strTime = [[NSString alloc] initWithFormat:@"%@",[formatter stringFromDate:date]]; 

    array = [[NSMutableArray alloc] initWithCapacity:0]; 
    [array addObject:strTime]; 
    [array count]; 
} 
+0

죄송합니다. 이미 자정이기 때문에 대답이 느릴 수 있습니다. – onion

+0

죄송합니다. 그러나 당신의 질문은별로 잘 쓰여져 있지 않습니다. 당신이 알고 싶은 것을 이해하는 것은 어렵습니다. 게다가 자정이라면 미국에 살지 않는 것 같아 영어 실력이 좋지 않을 수도 있습니다. 어느 쪽이든, 나는 당신의 질문을보다 명확하고 간결하게 다시 쓰도록 제안 할 것입니다. – Josiah

+1

사진이 도움이 될 수있는 간단한 와이어 프레임을 그릴 수 있다면 그림이 천 단어를 말합니다. – Imran

답변

1

여기에서 달성하려는 계획을 정확히 모르겠습니다. 추가 단추를 눌렀을 때 시간을 표시하고 테이블보기의 제목 섹션에 표시하려고한다고 가정합니다. 코드는

@property (nonatomic, retain) NSString *dateString; 

있음 버튼 액션을 추가,

이 현재의 클래스 .H 파일의 날짜를 유지하기 위해 @property를 선언 같은

-(void)addButton 
{ 
    NSDate *date = [NSDate date]; 
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
    [formatter setDateStyle:NSDateFormatterMediumStyle]; //set the date format appropriately, Check SO for sample date formats. 

    self.dateString = [formatter stringFromDate:date]; 
    [self.tableView reloadData];//reload your table view to show this date in title 
} 

귀하의 섹션 제목 대리자를 찾습니다 방법은 다음과 같습니다.

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    if (section == 0) 
     return self.dateString;//modify this as per your requirement 
    else 
     return @"title"; 
} 

요구 사항에 맞게 위 코드를 조정하십시오.

관련 문제