我有2个屏幕。我的第一个屏幕正在加载第二个屏幕。第二个屏幕在表格视图中具有主题的名称。我想在模拟器底部添加3个按钮(不在表格下方)。这3个按钮将充当过滤器。当用户点击第一个按钮时,整个书籍将被该按钮事件过滤。我该如何添加按钮?我希望用户可以在表格视图中看到任意数量的行。
感谢
答案 0 :(得分:0)
您可以在视图底部添加三个 UIBarButtonItems 的 UIToolbar 。 This tutorial可能会对您有所帮助!
答案 1 :(得分: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;
}
}