使用 Data.plist 时向表添加公开按钮

发布于 2024-11-10 13:38:30 字数 4792 浏览 4 评论 0原文

我已经从 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

I've created a table from a data.plist and was trying to figure out how to add a disclosure button at the second level-to-third level table. It would be used to add a UIView "credits" to the student artists who made the picture. However, I need to make sure that the name can change as the table will house different files from different students. So for example, cases 1-3 would all be Aubrey's work, and cases 4-6 would be Josh's, etc.

Any help would be great.

#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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黎夕旧梦 2024-11-17 13:38:30

如果您想在单元格中指示公开,您可以使用属性 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;

If you want to indicate a disclosure in the cell you can make use of the property accessoryType.

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

Which can have any of these

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文