使用 Data.plist 时向表中添加披露按钮
Posted
技术标签:
【中文标题】使用 Data.plist 时向表中添加披露按钮【英文标题】:Adding Disclosure Buttons to a Table when using Data.plist 【发布时间】:2011-05-30 07:20:05 【问题描述】:我从 data.plist 创建了一个表格,并试图弄清楚如何在二级到三级表格中添加披露按钮。它将用于向制作图片的学生艺术家添加 UIView“学分”。但是,我需要确保名称可以更改,因为该表将容纳来自不同学生的不同文件。例如,案例 1-3 都是 Aubrey 的作品,案例 4-6 是 Josh 的作品,等等。
任何帮助都会很棒。
#import "RootViewController.h"
#import "DrillDownAppAppDelegate.h"
#import "DetailViewController.h"
#import "ImageViewController.h"
@implementation RootViewController
@synthesize tableDataSource, CurrentTitle, CurrentLevel;
- (void)viewDidLoad
[super viewDidLoad];
if(CurrentLevel == 0)
//Initialize our table data source
NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];
DrillDownAppAppDelegate *AppDelegate = (DrillDownAppAppDelegate *)[[UIApplication sharedApplication] delegate];
self.tableDataSource = [AppDelegate.data objectForKey:@"Rows"];
self.navigationItem.title = @"Electromagnetism";
else
self.navigationItem.title = CurrentTitle;
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
return 1;
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return [self.tableDataSource count];
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
// Set up the cell...
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
cell.text = [dictionary objectForKey:@"Title"];
return cell;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:@"Children"];
if([Children count] == 0)
NSInteger ViewNumber = [[dictionary objectForKey:@"View"] integerValue];
switch (ViewNumber)
case 1:
ImageViewController *ivc = [[ImageViewController alloc] initWithNibName:@"ImageView" bundle:[NSBundle mainBundle]];
ivc.ImageName = @"Magnets_History_Aubrey.jpg";
[self.navigationController pushViewController:ivc animated:YES];
[ivc release];
break;
case 2:
ImageViewController *ivc = [[ImageViewController alloc] initWithNibName:@"ImageView" bundle:[NSBundle mainBundle]];
ivc.ImageName = @"Magnets_Theory_Aubrey.jpg";
[self.navigationController pushViewController:ivc animated:YES];
[ivc release];
break;
case 3:
ImageViewController *ivc = [[ImageViewController alloc] initWithNibName:@"ImageView" bundle:[NSBundle mainBundle]];
ivc.ImageName = @"Magnets_AU_Aubrey.jpg";
[self.navigationController pushViewController:ivc animated:YES];
[ivc release];
break;
default:
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
break;
else
//Prepare to tableview.
RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
//Increment the Current View
rvController.CurrentLevel += 1;
//Set the title;
rvController.CurrentTitle = [dictionary objectForKey:@"Title"];
//Push the new table view on the stack
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource = Children;
[rvController release];
- (void)dealloc
[tbController release];
[CurrentTitle release];
[tableDataSource release];
[super dealloc];
@end
【问题讨论】:
【参考方案1】:如果您想在单元格中指明披露,您可以使用属性accessoryType
。
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
可以有这些
typedef enum
UITableViewCellAccessoryNone, // don't show any accessory view
UITableViewCellAccessoryDisclosureIndicator, // regular chevron. doesn't track
UITableViewCellAccessoryDetailDisclosureButton, // blue button w/ chevron. tracks
UITableViewCellAccessoryCheckmark // checkmark. doesn't track
UITableViewCellAccessoryType;
【讨论】:
感谢 7KV7。通过将蓝色按钮添加到 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath ,我得到了雪佛龙的蓝色按钮,但它也显示在第一级。我如何才能更改或删除上面的代码? 如果你不想显示这个 cell.accessoryType = UITableViewCellAccessoryNone; 嗯,这是我的问题的一半。所以我使用data.plist 生成一个表。基本上是三层。在第一层,它进入三个第二层。第一层不需要披露按钮。只有第二层可以。 是的,您可以根据您的等级提供上述代码。根据层,指定accessoryType 我仍然对在哪里添加它感到困惑,因为所有级别都有按钮。我只想要第二级。以上是关于使用 Data.plist 时向表中添加披露按钮的主要内容,如果未能解决你的问题,请参考以下文章
SQLserver 向表中添加工作日,不排除节假日,只排出星期六星期日