我刚刚注意到,当我在Xcode(基于视图的应用程序,基于窗口的应用程序等)中使用标准模板创建iPhone应用程序时,头文件只导入UIKit.h(而不是Foundation.h).因此,如果未导入Foundation.h文件,如何在程序中使用NSString,NSArray等基础类?不应该抛出错误吗?
有什么区别
self.myObject = nil;
Run Code Online (Sandbox Code Playgroud)
和
[myObject release];
Run Code Online (Sandbox Code Playgroud)
另外,为什么前者通常在viewDidUnload方法中使用,后者在dealloc方法中使用?
有没有办法可以在UITableViewCell中更改textLabel和detailTextLabel之间的间距?(没有子类化UITableViewCell)
我真的无法在MVC中获得模型对象的悬念.我想知道为什么我们不能只使用数组和字典以及字典数组?
我知道它们代表了我的其他类操作和使用的"数据".但他们应该构建的正确方法是什么?假设我有一个我想读的plist并在表视图中显示.我可以直接将它加载到我的viewDidLoad方法中的数组属性中,然后使用它,对吧?我为什么要使用Model类,我将如何构建它?
此外,任何解释这一点的资源/博客链接将不胜感激!
我正在尝试使用此示例学习在我的Xcode项目中创建和使用静态库.但是我一直在犯这个错误:
ld: warning: ignoring file /Developer/MathTest/iCodeBlogsMathLibrary/libICodeMathUtils.a,
missing required architecture i386 in file
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MathFunctions", referenced from:
objc-class-ref in MathTestViewController.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我可能会失踪什么?
以下陈述有什么问题?
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *title;
switch (section)
{
case 0:
title = @"Section 1";
break;
case 1:
title = @"Section 2";
break;
default:
break;
}
return title;
}
Run Code Online (Sandbox Code Playgroud)
为什么在分析此代码时会出现"未定义或垃圾值返回给调用者"的逻辑错误?
我有这样一种在Constants.h文件中定义的枚举:
typedef enum {
CalendarTypeMonth = 0,
CalendarTypeWeek
} CalendarType;
Run Code Online (Sandbox Code Playgroud)
然后在我的视图控制器中,我确定日历类型应该是什么,并以这种方式将其存储在属性中:
@property (nonatomic) CalendarType myCalendarType;
Run Code Online (Sandbox Code Playgroud)
现在我希望项目中的所有类都可以访问日历类型.如何将此属性设置为global/extern,以便所有类都可以读取此内容?
编辑:我知道整个项目将提供枚举的定义.但我感兴趣的是价值myCalendarType.如何在所有类中访问myCalendarType的值?
我一直在努力维护一个列表,列出我在开发过程中遇到的所有错误消息及其常见原因和修复.您遇到的常见错误消息(以及不常见的错误消息)是什么?如何修复它们?
双击主页按钮的确是什么?
我在Info.plist文件中实现了"应用程序不在后台运行".尽管如此,我的应用程序显示双击主页按钮!是的,我尝试过干净的构建.
我们可以只使用NSString对象作为NSDictionary中的键吗?我们如何知道哪些对象可以使用哪些不可以使用?
我已经创建了一个UITableViewCell子类,如下所示.我所做的就是在单元格的内容视图中添加一个标签并设置其文本.
#import <UIKit/UIKit.h>
@interface CustomTableViewCell : UITableViewCell {
}
@end
#import "CustomTableViewCell.h"
@implementation CustomTableViewCell
@synthesize horizontalTableView;
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
UIView *myContentView = self.contentView;
UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
l.text = @"Hi";
[myContentView addSubview:l];
[l release];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
现在,我以这种方式在表格视图中使用此自定义单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"MyCell";
CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[CustomTableViewCell alloc] initWithFrame:CGRectMake(0, 0, 50, 300) …Run Code Online (Sandbox Code Playgroud) 我想替换自定义单元格触摸的单元格.我通过调用reloadRowsAtIndexPaths来做到这一点
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Row selected: %d", [tableView indexPathForSelectedRow] row]);
NSLog(@"Section selected: %d", [tableView indexPathForSelectedRow] section]);
//return a custom cell for the row selected
}
Run Code Online (Sandbox Code Playgroud)
当我尝试从cellForRowAtIndexPath中访问/记录indexPathForSelectedRow时,无论我选择哪个单元格,它都会返回0,0.为什么是这样?
ios ×10
objective-c ×10
iphone ×7
uitableview ×3
foundation ×2
cocoa-touch ×1
debugging ×1
model ×1
xcode ×1
xcode4 ×1