2011-07-07 25 views
0

我有2个屏幕。我的第一个屏幕正在加载第二个屏幕。第二个屏幕在表格视图中包含主题名称。我想在模拟器的底部添加3个按钮(不在桌子下面)。这3个按钮将用作过滤器。当用户点击第一个按钮时,整个书籍将被该按钮事件过滤。我将如何添加按钮?我想让按钮在表格视图中显示任意数量的行。如何在表格视图中设计按钮

感谢

+0

按钮按钮的点击重新加载的tableview? – ibiza

回答

0

您可以在视图的底部添加UIToolbar有三个UIBarButtonItemsThis tutorial可能会帮助你进一步!

+0

伟大的教程 –

0

您可以使用区段控制与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

任何代码将apperciate –

+0

检查编辑答案 – iProgrammer

相关问题