您的位置:首页 > 编程语言

码代码时碰到的一些小问题 & Xcode的一些使用方法

2012-09-14 15:04 696 查看
[b]我还是菜鸟,写下的记录不一定完全正确。多找资料,多google吧。[/b]

Xcode 4.3.2

1、添加Frameworks,或者看图

View Code

#pragma mark - UIAlertViewDelegate
- (void)willPresentAlertView:(UIAlertView *)alertView
{
[self.textField resignFirstResponder];
}

// 某处
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告"
message:@"不能为空"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];


28、@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;

在- (NSFetchedResultsController *)fetchedResultsController中调用:

NSLog(@"%i", _fetchedResultsController.fetchedObjects.count);


第一次:0;

第二次:!=0;(在其他方法中调用)。

如果:

[_fetchedResultsController performFetch:&error]; // add this line
NSLog(@"%i", _fetchedResultsController.fetchedObjects.count);


第一次:!=0;

第二次:!=0;(在其他方法中调用)。

猜测,刚初始化后没有执行 performFetch 操作。

29、为什么需要在Core Data 中的 Entities 之间的 Relationship 指定 Inverse?

Core Data uses bidirectional relationship information to maintain the consistency of the object graph (hence the Consistency Error) and manage undo and redo information. If you leave a relationship without an inverse, you imply that you will take care of the object graph consistency and undo/redo management. The Apple documentation strongly discourages this, however, especially in the case of a tomany relationship. When you don’t specify an inverse relationship, the managed object at the other end of the relationship isn’t marked as changed when the managed object at this end of the relationship changes.(摘自《Pro.Core.Data.for.iOS. Second.Edition》)

30、是否需要实现 NSMangedobject 子类中的比如 add<Key>Object 和 remove<Key>s 方法?

描述:

@interface Employee (DirectReportsAccessors)
- (void)addDirectReportsObject:(Employee *)value;
- (void)removeDirectReportsObject:(Employee *)value;
- (void)addDirectReports:(NSSet *)value;
- (void)removeDirectReports:(NSSet *)value;
@end


不需要。

Managed Object Accessor Methods,《Core Data Programming Guide》。

There should typically be no need for you to provide your own implementation of these methods, unless you want to support scalar values. The methods that Core Data generates at runtime are more efficient than those you can implement yourself.

31、《Core Data’s default date value》

默认值可以使用带双引号的词,形式如“now”,但是时间在编译时决定,而不是运行时。

32、Core Data:在使用NSFetchedResultsController的情况下,在self.managedObjectContext保存后,没有保存在到持久性存储中?

应该这样:

NSError *error;
NSManagedObjectContext *addingManagedObjectContext = controller.managedObjectContext;

if (![addingManagedObjectContext save:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
if (![[self.fetchedResultsController managedObjectContext] save:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}


原因:

The new managedObject is associated with the add controller's managed object context.
This means that any edits that are made don't affect the application's main managed object context -- it's a way of keeping disjoint edits in a separate scratchpad. Saving changes to that context, though, only push changes to the fetched results controller's context. To save the changes to the persistent store, you have to save the fetch results controller's context as well.


摘自Apple‘s SampleCode。

33、error occurred when I execute “self.course.referenceBooks.count”

描述见链接。

原因:由于手动建立的model file,关系名(books)和Course类中的属性不一致导致。

34、Creating Source Code to Implement a Custom Managed Object Class

创建源代码用于实现自定义的 Managed Object 类。

35、在创建源代码用于实现自定义的 Managed Object 类的时候,有着一个选项:use scalar properties for primitive data types

使用 scalar properties ,Core Data 不会动态生成 accessor methods,即需要自己手动实现。

链接

文档链接

36、Insert a Table Header View (tableHeaderView) in StoryBoard

拖动控件至导航栏与表视图之间。类似的界面可通过在ViewController中添加视图控件和表示图控件,但效果没之间插入表头视图好。



37、在使用UITableView时,当数据发生改变后,最好执行 [self.tableView reloadData];;其他,见4

38、隐藏self.navigationItem.backBarButtonItem

self.navigationItem.hidesBackButton = NO;


Xcode 4.5.2

39、在UIScrollView中添加图片,在代码中能实现预期的效果,而在SB中好UIScrollView则会使它的frame变形,它的高度比图片的高度高很多时才不报错。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐