我在这里有一个任务,我应该
创建一个应用程序,将所有粘贴板项目复制到其中 一张桌子,深入到所述粘贴板项目的详细视图中
下面,我将为您提供RootViewController.m
文件的代码。该计划不起作用,并在此行SIGABRT
中误给我cell.textLabel.text = cellValue;
。
你能告诉我,这里可能有什么问题,并提前感谢你。
#import "RootViewController.h"
@implementation RootViewController
@synthesize detailsViewController;
NSArray* pasteBoardItems;
- (void)viewDidLoad
{
// Get a reference to the system pasteboard
UIPasteboard* pasteBoard = [UIPasteboard generalPasteboard];
NSLog(@"%@", pasteBoard.items);
pasteBoardItems = [pasteBoard.items valueForKey:@"public.utf8-plain-text"];
pasteBoardItems = [pasteBoard.items valueForKey:@"public.item (kUTTypeItem)"];
self.navigationItem.title = @"Pasteboard";
[super viewDidLoad];
}
- (void)dealloc
{
[pasteBoardItems release];
[super dealloc];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [pasteBoardItems 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] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue = [pasteBoardItems objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
// Configure the cell.
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString *rowValue = [pasteBoardItems objectAtIndex:row];
NSString *message = [[NSString alloc] initWithFormat:@"You have selected \"%@\"",rowValue];
if(self.detailsViewController == nil){
DetailsViewController *d = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:[NSBundle mainBundle]];
self.detailsViewController = d;
[d release];
}
[self.detailsViewController initWithTextSelected:message];
[self.navigationController pushViewController:self.detailsViewController animated:YES];
}
@end
答案 0 :(得分:0)
SIGABRT
在大多数情况下意味着您要访问已发布的对象。
在您的情况下,我建议在[pasteBoardItems retain];
方法的末尾添加第- (void)viewDidLoad
行。