как обновить viewForFooterInSection - PullRequest
0 голосов
/ 21 апреля 2011
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {  

    if(footerView == nil) {
        //allocate the view if it doesn't exist yet
        footerView  = [[UIView alloc] init];


        UIImage *image = [[UIImage imageNamed:@"update.png"]
                          stretchableImageWithLeftCapWidth:8 topCapHeight:8];

        //create the button
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setBackgroundImage:image forState:UIControlStateNormal];

        //the button should be as big as a table view cell
        [button setFrame:CGRectMake(100, 3, 300, 50)];

        NSDate *today = [NSDate date];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        NSString *currentTime = [dateFormatter stringFromDate:today];


        [dateFormatter release];
        NSLog(@"User's current time in their preference format:%@",currentTime);

        NSString *btnString;


        NSDate* now = [NSDate date];
                btnString = [NSString stringWithFormat:@"%@:%@",@"Update",currentTime];     


        //set title, font size and font color
        [button setTitle:btnString forState:UIControlStateNormal];
        [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

        //set action of the button
        [button addTarget:self action:@selector(update:)
         forControlEvents:UIControlEventTouchUpInside];

        [footerView addSubview:button];

    }
    return footerView;  
}  

здесь я пытаюсь добавить кнопку в нижнем колонтитуле, и кнопка содержит текст как «Update: currentTime» -> например, «Update: 16:30»
, чтобы пользователь понял, когда он делал последнее обновление, ноТеперь, когда я нажимаю эту кнопку, обновление выполняется в поле зрения, но я также хочу обновить (обновить) текст кнопки, например, если я нажму кнопку через 15 минут, на ней может отобразиться «Обновление: 16:45» ... как обновитьэтот текст

большое спасибо

1 Ответ

3 голосов
/ 21 апреля 2011

Ваш метод "update:" получит кнопку как отправителя.Отправитель должен быть в качестве объекта id, затем вы можете привести его к UIButton * и обновить его текст так, как вам нужно:

void update:(id)sender {    
[(UIButton)*sender setTitle:@"NEW TEXT" forState:UIControlStateNormal];
//rest of your update code
}
...