Как оформить кнопки в табличном представлении - PullRequest
0 голосов
/ 07 июля 2011

У меня 2 экрана. Мой первый экран загружает второй экран. Второй экран имеет имя субъекта в виде таблицы. Я хочу добавить 3 кнопки внизу симулятора (не ниже таблицы). Эти 3 кнопки будут действовать как фильтр. Когда пользователь нажимает первую кнопку, целые книги будут отфильтрованы по событию этой кнопки. Как я буду добавлять кнопки? Я хочу сделать кнопки видимыми пользователям для любого количества строк в табличном представлении.

спасибо

Ответы [ 2 ]

0 голосов
/ 07 июля 2011

Вы можете использовать элементы управления «Сегмент» с 3 сегментами и перезагрузить просмотр таблицы при нажатии каждой кнопки

код

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    //different rows for each section and for different selected segment value
 switch (segmentedControl.selectedSegmentIndex) {
     case 0:
         return [arrayOfRestaurants count]; //counting number of restaurants
         break;
    case 1:
        return [arrayOfHotels count]; //counting number of hotels

             break;

    case 2:
         return [arrayOfPlaces count]; //counting number of famous place
             break;


 }
    return 0;

}
- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *CellIdentifier = @"Cell";


    UITableViewCell *cell = nil;



    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                       reuseIdentifier:CellIdentifier]autorelease];// cell intialization

    [cell.textLabel setFont:kFont];

    [cell.textLabel setTextColor:[UIColor colorWithRed:0 green:0 blue:80/255.0 alpha:1.0]];
    [cell.detailTextLabel setFont:[UIFont fontWithName:@"Arial" size:13.0]];

    [cell.detailTextLabel setTextColor:[UIColor whiteColor]];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //set up cell for different selected segments...

    cell.backgroundColor = [UIColor clearColor];
    switch (segmentedControl.selectedSegmentIndex) {
        case 0:
            NSLog(@"For Restaurants List");
            Restaurants *restaurants = [arrayOfRestaurants objectAtIndex:indexPath.row]; //getting list of restaurants

             //setting name of restaurnats to string

            cell.textLabel.text = restaurants.Name;
            cell.detailTextLabel.text = restaurants.Address; //detail textlabel to display address
            break;

        case 1:
            NSLog(@"For Hotels List");
            Hotel *hotels = [arrayOfHotels objectAtIndex:indexPath.row]; //getting list of hotels
            cell.textLabel.text = hotels.Name;
            cell.detailTextLabel.text = hotels.Address;//address of hotel
            break;

        case 2:
            NSLog(@"For Places List");
            Famousplaces *famousPlaces = [arrayOfPlaces objectAtIndex:indexPath.row];//getting list of famous places
            cell.textLabel.text = famousPlaces.Name; //name of famous place
            break;

    }   

    return cell;



}

//segment control value changed method
- (IBAction) segmentedControlIndexChanged {

    switch (segmentedControl.selectedSegmentIndex) {
        case 0:
            [tableView reloadData];//reloading table on selected segment
            break;

            case 1:
            [tableView reloadData];

                break;

            case 2:
            [tableView reloadData];
                break;

        default:
            break;
    }




}
0 голосов
/ 07 июля 2011

Вы можете добавить UIToolbar с тремя UIBarButtonItems в нижней части экрана. Этот урок может помочь вам в дальнейшем!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...