gpt4 book ai didi

ios - 使用 UITable 链接到笔记本应用程序中的不同页面 (iOS)

转载 作者:行者123 更新时间:2023-11-29 04:34:31 25 4
gpt4 key购买 nike

我正在为 iPad 制作一个笔记应用程序,它可以让用户画线,现在,它可以通过将每个页面保存为 PNG 格式在文档目录中来保存笔记本的页面。这是我必须保存图像的代码:

- (IBAction)saveImage:(id)sender {

UIImage *saveImage = drawImage.image;

if (saveImage != nil)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat: @"%@-%d.png", @"image", numberOfPages] ];
NSData* data = UIImagePNGRepresentation(saveImage);
[data writeToFile:path atomically:YES];
}

}

顺便说一句,numberOfPages 是一个 int,每次按下“新页面”按钮时都会加 1,这样,每个图像都被命名​​为“image1”、“image2” ”等

所以我的问题是:如何设置 UITable 以便用户可以看到他们创建的所有页面的列表。

非常感谢您的宝贵时间,

卡尔

最佳答案

每次创建新页面时,都将带有图像名称的字符串添加到数组中。然后,迭代该数组以填充 UITableView。当用户选择一个单元格时,打开具有该名称的文件。

#import "RootViewController.h"

@implementation RootViewController
@synthesize keys, names;
AppDelegate *appD;

- (void)viewDidLoad
{
[super viewDidLoad];
appD = (AppDelegate *)[[UIApplication sharedApplication] delegate];
names = appD.data;
NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
keys = array;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return [keys count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];
return [nameSection count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section = indexPath.section;
NSUInteger row = indexPath.row;

NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [appD.data objectForKey:key];

static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [nameSection objectAtIndex:row];
return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *key = [keys objectAtIndex:section];
key = [key substringFromIndex:2];
return key;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section = indexPath.section;
NSUInteger row = indexPath.row;

NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [appD.data objectForKey:key];

appD.theInfo.primary = [nameSection objectAtIndex:row];

[self performSegueWithIdentifier:@"secondarySegue" sender:self];
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

@end

这适用于导航 Controller 中的表格,该表格从 .plist 填充自身,并在单击单元格时移动到另一个表格。 TableView 通过委托(delegate)和数据源导出连接到 View Controller 。

关于ios - 使用 UITable 链接到笔记本应用程序中的不同页面 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11249806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com