我输入时没有错误
char a[10] = "Hi";
Run Code Online (Sandbox Code Playgroud)
但是当我将其更改为以下内容时,我收到错误: Array type char is not assignable.
char a[10];
a = "Hi";
Run Code Online (Sandbox Code Playgroud)
为什么数组类型char不可分配?是因为语言是故意写的还是我错过了一点?
我有一个程序,其中有一个tableViewController,它有1个部分和3行.每当我运行应用程序时,它总是在dequeueReusableCellWithIdentifier:方法崩溃.我插入了一个断点,并NSLog()在此方法中为零.我还将Cell Identifier故事板中的原型单元设置为Cell.但程序仍然崩溃.这是导致问题的方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"indexPath.section = %d, indexPath.row = %d", indexPath.section, indexPath.row);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil)
{
NSLog(@"in nil");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
崩溃日志显示:
MyAppTake4[7463:707] indexPath.section = 0, indexPath.row = 0
2012-11-05 23:21:20.747 MyCardAppTake4[7463:707] -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector sent to instance 0xfbc9000
2012-11-05 23:21:20.753 MyCardAppTake4[7463:707] *** Terminating app due to …Run Code Online (Sandbox Code Playgroud) @interface Foo : NSObject
{
extern int gGlobalVar;
int i;
}
-(void)setgGlobalVar:(int)val;
@end
@implementation Foo
-(void)setgGlobalVar:(int)val
{
i = 5;
NSLog(@"i = %i", i);
gGlobalVar = val;
}
@end
Run Code Online (Sandbox Code Playgroud)
我可以i在接口中声明并在实现中使用它而没有任何错误.但是我不能extern在接口中声明类型的变量.为什么会这样?为什么我会收到一个错误:"类型名称不允许指定存储类"?
我试图使用NSLog显示存储特定枚举值的值.在下面的示例中,我尝试将输出作为:5 represents month of May.
知道什么是用于enumNSLog 的正确令牌?我尝试使用%i和%@,但两者都不起作用.
谢谢!
enum month {jan = 1, feb, march, apr, may, jun, jul, aug, sep, oct, nov, dec};
enum month amonth;
int x = 5;
amonth = x;
NSLog(@"%i represents month of %@", x,amonth);
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个涉及tableView的简单程序.当我单击tableView中的单元格时,它应该显示有关单击的单元格的更多信息DetailedViewController.但是,当我单击单元格时,它仍然会突出显示,并且不会显示单元格的信息.所以我用NSLog()语句来确定程序卡在哪里.NSLog()我在didDeselectRowAtIndexPath方法中引入的语句表明我得到了在最后一个之前单击的单元格的响应.
知道为什么会这样吗?另外,为什么单击单元格时看不到DetailedViewController?
为简洁起见,Numbers.h包含两个变量:NSString * name和int long long number.DetailedViewController是一个带有两个标签的简单VC:nameField并且numberField当我单击相应的单元格时,它们会被更新.
我真诚地感谢任何帮助.谢谢.
#import "SecondViewController.h"
#import "DetailedViewController.h"
#import "Numbers.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize numberList;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSLog(@"loaded Nib file");
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"View Numbers";
self.tabBarItem.image = [UIImage imageNamed:@"second"];
}
return self;
}
- (void)viewDidLoad
{
NSLog(@"Loaded view controller");
Numbers *num1 = [[Numbers …Run Code Online (Sandbox Code Playgroud)