我试图检查我将用作URL的字符串是否以http开头.我现在试图检查的方式似乎不起作用.这是我的代码:
NSMutableString *temp = [[NSMutableString alloc] initWithString:@"http://"];
if ([businessWebsite rangeOfString:@"http"].location == NSNotFound){
NSString *temp2 = [[NSString alloc] init];
temp2 = businessWebsite;
[temp appendString:temp2];
businessWebsite = temp2;
NSLog(@"Updated BusinessWebsite is: %@", businessWebsite);
}
[web setBusinessWebsiteUrl:businessWebsite];
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我一直在处理一个应用程序,它一直工作正常,直到Xcode下载库或其他东西,然后它开始出现问题.我只是想创建getter/setter方法来从我的APPDelegate中获取几个数组.就像我说它工作正常然后随机出现这个错误现在将不再构建:
property with 'retain(or strong)' attribute must be of object type
Run Code Online (Sandbox Code Playgroud)
这是代码的其余部分:
#import <Foundation/Foundation.h>
#import "Project.h"
#import "TeamMember.h"
@interface Task : NSObject{
NSDate *endDate;
NSDate *startDate;
NSMutableString* notes;
NSMutableString* taskName;
//The error appears first right here over teamMember
TeamMember *teamMember;
Project *project;
}
//The error appears over both of the following lines as well...
@property (nonatomic, retain)TeamMember *teamMember;
@property (nonatomic, retain) Project * project;
@property (nonatomic, retain) NSMutableString *notes;
@property (nonatomic, retain) NSMutableString *taskName;
@property (nonatomic, retain) NSDate *startDate;
@property …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何将MKAnnotation的实例添加到MKMapView.我无法弄清楚我做错了什么......一切似乎都没问题,直到我真的尝试将注释添加到mapView.然后我收到SIGABRT错误.这是我的代码:
lon = [[attributeDict objectForKey:@"long"] doubleValue];
lat = [[attributeDict objectForKey:@"lat"] doubleValue];
MKPointAnnotation *point;
CLLocation *theLocation = [[CLLocation alloc]initWithLatitude:lat longitude:lon];
CLLocationCoordinate2D location;
location.latitude = lat;
location.longitude = lon;
[point setCoordinate:(location)];
[point setTitle:businessName];
//ITS RIGHT HERE THAT I GET THE ERROR
[theMap addAnnotation:point];
Run Code Online (Sandbox Code Playgroud)
你必须首先设置地图的区域吗?
嘿,我无法弄清楚我得到的错误.我让我的应用程序工作,然后我不知道我做了什么,但现在不会打开,而是我收到此错误:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TaskViewController 0x16c9b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key projectToolBar.'
Run Code Online (Sandbox Code Playgroud)
任何想法可能是什么问题?如果我需要,我可以添加我的项目代码......
所以我查看并在界面构建器/故事板中有一个指向projectToolBar的链接,该链接在头文件中没有对应的行.我删除了IB中的问题,但是,现在我收到一个新错误,但它仍然无法正常工作.
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TaskViewController 0x132dd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key projectView.'
Run Code Online (Sandbox Code Playgroud)
这是我的taskviewController类:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "newTaskWindow.h"
@interface TaskViewController : UIViewController <DismissPopoverDelegate>{
IBOutlet UIScrollView *taskScrollView;
AppDelegate * _appDelegate;
UIDeviceOrientation orientation;
IBOutlet UIView *newTaskView;
IBOutlet UIBarButtonItem *newTaskButton;
IBOutlet UIBarButtonItem *newTeamMemberButton;
IBOutlet UIBarButtonItem …Run Code Online (Sandbox Code Playgroud) 所以我尝试将参数传递给我的"buttonClicked"函数,以便我可以动态控制单击按钮时发生的情况.我尝试自己做的每一种方式都会破坏我的代码.我在stackOverflow上搜索过很多不同的网站和答案,但我似乎无法找到答案.我对目标C相当新,特别是对于函数,所以我真的可以使用一些帮助来弄清楚如何做到这一点.提前致谢
这是我到目前为止的代码以及我要做的事情:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
NSLog(@"Hi 1!");
[button addTarget:self action:@selector(buttonClicked:buttonType:buttonID:) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(buttonViewXvalue, buttonViewYvalue, buttonViewWidth, buttonViewLength);
[self.view addSubview:button];
Run Code Online (Sandbox Code Playgroud)
然后在头文件中的声明:
- (IBAction)buttonClicked:(id)sender theButtonType: (int)buttonType: theButtonID: (int) buttonID;
Run Code Online (Sandbox Code Playgroud)
和实施:
- (IBAction)buttonClicked:(id)sender theButtonType: (int)buttonType: theButtonID: (int) buttonID
{
//Here I would use the buttonType and buttonID to create a new view.
NSLog(@"Hi!");
}
Run Code Online (Sandbox Code Playgroud) 在我当前的应用程序中,当我单击工具栏按钮时,我正在尝试创建一个菜单屏幕apear.我发现最好的方法是使用UIPopoverController来显示我创建的自定义视图.但是,关于我当前代码的一些内容存在缺陷.当我运行我的应用程序并按下按钮时,我收到一条错误消息,表示当弹出窗口仍然可见时它正在达到dealoc.即使看了几个类似问题的例子,我也不能为我的生活弄清楚如何解决这个问题.这是我的代码:
-(IBAction)newMenu:(id)sender{
newTaskWindow *newTaskWin = [[newTaskWindow alloc]init];
UIView *test = [[UIView alloc]init];
test = newTaskWin.view;
UIPopoverController *taskPop = [[UIPopoverController alloc]initWithContentViewController:newTaskWin];
[taskPop setDelegate:self];
[taskPop presentPopoverFromBarButtonItem:newTaskButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[taskPop setPopoverContentSize:CGSizeMake(400, 500)];
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?提前致谢
}
这是它产生的错误:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '- [UIPopoverController dealloc] reached while popover is still visible.'
*** First throw call stack:
(0x381fb8bf 0x37d471e5 0x381fb7b9 0x381fb7db 0x32065f71 0x37d430c5 0x37d44db7 0x2ecf 0x38155435 0x31cbe9eb 0x31d843cf 0x38155435 0x31cbe9eb 0x31cbe9a7 0x31cbe985 0x31cbe6f5 0x31cbf02d 0x31cbd50f 0x31cbcf01 0x31ca34ed 0x31ca2d2d 0x37f29df3 0x381cf553 0x381cf4f5 0x381ce343 …Run Code Online (Sandbox Code Playgroud)