我有2個屏幕。我的第一個屏幕正在加載第二個屏幕。第二個屏幕在表格視圖中包含主題名稱。我想在模擬器的底部添加3個按鈕(不在桌子下面)。這3個按鈕將用作過濾器。當用戶點擊第一個按鈕時,整個書籍將被該按鈕事件過濾。我將如何添加按鈕?我想讓按鈕在表格視圖中顯示任意數量的行。如何在表格視圖中設計按鈕
感謝
我有2個屏幕。我的第一個屏幕正在加載第二個屏幕。第二個屏幕在表格視圖中包含主題名稱。我想在模擬器的底部添加3個按鈕(不在桌子下面)。這3個按鈕將用作過濾器。當用戶點擊第一個按鈕時,整個書籍將被該按鈕事件過濾。我將如何添加按鈕?我想讓按鈕在表格視圖中顯示任意數量的行。如何在表格視圖中設計按鈕
感謝
您可以使用區段控制與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;
}
}
任何代碼將apperciate –
檢查編輯答案 – iProgrammer
按鈕按鈕的點擊重新加載的tableview? – ibiza