我试图实现下面的代码,但没有成功.基本上,我想设置显示名称,thisPhoto.userFullName如果它不是'空白',否则显示thisPhoto.userName.
UILabel *thisUserNameLabel = (UILabel *)[cell.contentView viewWithTag:kUserNameValueTag];
NSLog(@"user full name %@",thisPhoto.userFullName);
NSLog(@"user name %@",thisPhoto.userName);
if (thisPhoto.userFullName && ![thisPhoto.userFullName isEqual:[NSNull null]] )
{
thisUserNameLabel.text = [NSString stringWithFormat:@"%@",thisPhoto.userFullName];
}
else if (thisPhoto.userFullName == @"")
{
thisUserNameLabel.text = [NSString stringWithFormat:@"%@",thisPhoto.userName];
}
Run Code Online (Sandbox Code Playgroud)
目前,即使userFullName是空白,我userName仍然没有显示在屏幕上.
我最近开始使用NSNotifications:
[[NSNotificationCenter defaultCenter] postNotificationName: selector: object:]; ....
Run Code Online (Sandbox Code Playgroud)
我发现它是视图控制器之间通信的一个很棒的概念.NSNotification对于应用程序中的所有通信来说,使用s 似乎有点太容易了.
如果我NSNotification在我的应用程序中使用s进行大部分工作,您认为对于太多这些工作的开销是多少?
我想把我UIImageView从左到右移动,反之亦然.我使用以下代码完成了一半:
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:10];
[UIView setAnimationRepeatAutoreverses:YES];
CGPoint pos = mover.center;
pos.x = 100.0f;
mover.center = pos;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
哪里mover是UIImageView.我面临的问题是我无法完全从左向右移动它.上面的代码只是从右到中移动它.我想从中心向左走.有人可以指导我吗?
在Objective-C 2.0编程一书的第326页上,作者说:
myNumber = [[NSNumber alloc] initWithInt: 1000];
Run Code Online (Sandbox Code Playgroud)
当然,根据之前的讨论,如果您以
myNumber这种方式创建,那么当您使用以下语句完成后,您有责任随后将其释放:
[myNumber release];
Run Code Online (Sandbox Code Playgroud)
我的问题是:
这是否意味着如果我NSNumber用这个语句创建一个对象
NSNumber *myNumber = [NSNumber numberWithInteger: 100];
Run Code Online (Sandbox Code Playgroud)
我不必myNumber自己发布这个对象?
我有这个代码,它正如所期望的那样工作:
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
但是,对于这一行:
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
Run Code Online (Sandbox Code Playgroud)
我收到警告(不是错误):
找不到'-renderInContext'方法.
如果实际上该方法有效,我怎么能得到这个警告呢?如果我只是简单地注释掉这一行,我的代码就会失败; 很明显,这条线,以及方法,实际上是有效的.
cocoa-touch core-animation objective-c compiler-warnings ios
我想在我的应用程序中添加一个简单有限的Twitter功能:应用程序的用户输入他的Twitter用户名和密码以及推文文本,然后按下按钮并发送推文.我的应用可以处理成功或失败的通知(例如,如果密码或用户名无效).
我保证我已经观看了一百个YouTube视频并搜索了网络.有没有人看过一个简单的教程或演示文稿,允许我这样做?
如果我有一个NSMutableArrayor NSMutableDictionary并将其传递给方法a la:
-(void)addToThisArray:(NSMutableArray *)theMutableArray
{
[theMutableArray addObject:@"test"];
}
Run Code Online (Sandbox Code Playgroud)
并称之为:
NSMutableArray *theMutableArrayToPass = [[NSMutableArray alloc] init];
[theMutableArrayToPass addObject:@"2"];
[self addToThisArray:theMutableArrayToPass];
Run Code Online (Sandbox Code Playgroud)
这是改变一个NSMutableArray或有效的方法NSMutableDictionary吗?当然,我对数组/字典的作用要比这个例子多得多,但我习惯于Perl,我们一直都是通过引用传递的.
cocoa-touch objective-c nsmutablearray nsmutabledictionary ios
我有一个大班.总而言之,它只有一个其他类应该调用的方法,然后是一堆方法来执行不同的操作,具体取决于接收的数据类型..m文件变得如此之大,我想将其拆分.我的想法是将方法划分为不同的类别(每个类别将使用特定类型的数据).所以我做到了.
在主要方法里面我没有改变任何东西,所以线条如
[self methodNowInMyCategory];
Run Code Online (Sandbox Code Playgroud)
还在那里 不过,我现在得到在我的课的主文件警告,因为"实例方法-methodNowInMyCatefory未找到".主.h文件正在导入类别的.h文件,因此方法是可见的(Xcode为代码着色).该课程不承认它们是自己的.
有没有办法在类中使用在其中一个类别中声明的方法?如果没有,你会建议我采用哪种方法来解决我的问题?main方法接收文件路径,打开文件,分析内容,然后向其发送一个或多个方法.
我希望我UILabel的一半text是大胆的,一半是不大胆的.我怎样才能做到这一点?
我有一个按钮,UIView就像这样创建:
UIBarButtonItem *editButton =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:self
action:@selector(toggleEdit)];
self.navigationItem.rightBarButtonItem = editButton;
[editButton release];
Run Code Online (Sandbox Code Playgroud)
这是动作方法:
-(void) toggleEdit:(id)sender
{
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误
2011-09-02 15:27:13.362 blubb [15006:207] - [DatabaseSelectionViewController toggleEdit]:无法识别的选择器发送到实例0x5a29d80 2011-09-02 15:27:13.365 blubb [15006:207] *终止应用程序由于未被捕获异常'NSInvalidArgumentException',原因:' - [DatabaseSelectionViewController toggleEdit]:无法识别的选择器发送到实例0x5a29d80'
为什么会这样?
objective-c ×10
cocoa-touch ×8
ios ×8
uilabel ×2
categories ×1
class ×1
cocoa ×1
large-files ×1
methods ×1
selector ×1
twitter ×1
uiimageview ×1