我需要调用一个我定义为的方法:
-(IBAction)next:(id)sender{
...
}
Run Code Online (Sandbox Code Playgroud)
我想打电话给它 -[UIViewController viewDidload]
如何以编程方式调用此方法?
我有一个视图控制器类,必须实现几个协议.为了保持整洁,我习惯将每个协议的方法放在视图控制器类的一个类别中.
这次我从链接器收到警告,该类没有实现其中一个协议.这些方法在运行时工作,链接器似乎无法识别类别中的实现.
我在不同的项目中简化了类,我在同一个地方得到了同样的错误.
类标题:
#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
@interface TopVC : UIViewController
<
UINavigationControllerDelegate,
ABPeoplePickerNavigationControllerDelegate
>
{}
@end
Run Code Online (Sandbox Code Playgroud)
TopVC.m(未显示)是自动生成的,没有任何变化.的UINavigationControllerDelegate协议方法此类别中实施:
#import <Foundation/Foundation.h>
#import "TopVC.h"
@interface TopVC (UINavigationControllerDelegate)
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
@end
#import "TopVC+UINavigationControllerDelegate.h"
@implementation TopVC (UINavigationControllerDelegate)
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
NSLog(@"navigationController:willShowViewController:animated:");
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
NSLog(@"navigationController:didShowViewController:animated:");
}
@end
Run Code Online (Sandbox Code Playgroud)
链接器不会在此类别中抱怨此方法.但是,如果我尝试以ABPeoplePickerNavigationControllerDelegate相同的方式实现协议的类别,它抱怨:
#import "TopVC.h"
@interface TopVC (ABPeoplePickerNavigationControllerDelegate)
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker;
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person; …Run Code Online (Sandbox Code Playgroud) 我在iPhone上有一个复杂的核心数据图.用户实体有许多其他实体,它们彼此相关,具有多种关系等...
我的问题是当我删除用户实体时如何删除所有相关实体.
提前致谢!
你如何通过代码获取iPhone的当前位置?我需要使用GPS跟踪位置.
UIImageWriteToSavedPhotosAlbum有时只能工作.有时它有效,有时它不起作用,完全相同的功能.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
NSLog(@"Saving image to camera roll...");
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
NSLog(@"Done!"); }
Run Code Online (Sandbox Code Playgroud)
我正在使用UIImagePicker控制器来获取然后调用该函数的图像.
有时它会将其保存到相机胶卷上,有时则根本不会.
任何人有任何想法?
提前致谢.
编辑:
UIImageWriteToSavedPhotosAlbum的完成方法有时返回错误:
wait_fences: failed to receive reply: 10004003
Run Code Online (Sandbox Code Playgroud) 我用'DateFromComponents'设置了一个日期,当我把它读出来......它的错误.我必须把DAY设置为第二个或之后的任何东西,所以我得到正确的年份?!?我设置2011年,当我读它我得到2010年!
day = 1;
month = 1;
year = 2011;
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:day];
[components setMonth:month];
[components setYear:year];
NSDate *date = [gregorian dateFromComponents:components];
[gregorian release];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"DD MMMM YYYY"];
NSLog (@"hmm: %@",[dateFormatter stringFromDate:actDate]);
Run Code Online (Sandbox Code Playgroud)
-------我来了1 January 2010 /// 2010 not 2011!?!?
如何解决这个问题.
克里斯
我从数据存储中取出一些对象,但结果并不是我所期待的.我是CoreData的新手,但我相当肯定这应该有用.我错过了什么?
请注意,User是一个有效的托管对象,我将其头文件包含在此代码中,并且该UserID是该类的有效属性.
NSFetchRequest *requestLocal = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:messageManagedObjectContext];
[requestLocal setEntity:entity];
// Set the predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY UserID IN %@", userList];
[requestLocal setPredicate:predicate];
// Set the sorting
... sorting details removed but exist and are fine ...
// Request the data
NSArray *fetchResults = [messageManagedObjectContext executeFetchRequest:requestLocal error:&error];
[requestLocal release];
for (int i; i < [fetchResults count]; i++) {
[fetchResults objectAtIndex:i].UserID = ...<----HERE
}
Run Code Online (Sandbox Code Playgroud)
fetchResults不是User对象的数组吗?不会[fetchResults objectAtIndex:i]成为User对象吗?为什么在构建" 非结构或联合的成员'UserID'请求时"会出错?
对不起,如果这是一个基本错误,我显然缺少一些基本概念.我做了大量的搜索,看起来应该是正确的.(我也试过快速枚举,但它抱怨fetchResults项目不是有效的Objective C对象,我认为实际上是同样的错误.)
如何编写NSPredicate来获取与数组中的值匹配的行?例如:
[NSPredicate predicateWithFormat:@"UserName IN %@",UserIDArray];
Run Code Online (Sandbox Code Playgroud)
如果UserIDArray包含用户ID,如何获取与此数组中的值匹配的用户名?
我有一个UITabViewController设置有两个选项卡,第二个包含一个Web浏览器.键盘不会出现在我的应用程序中,除非我首先UIAlertView在第一个选项卡中显示和关闭a .什么可能是错的?
这是在c的采访中向我提出的问题:
#include<stdio.h>
void main(){
char *ch;
ch=fun1();
printf(ch);
}
fun1(){
char *arr[100];
strcpy(arr,"name");
return arr;
}
Run Code Online (Sandbox Code Playgroud)
我得到了上述程序,并被要求弄清楚上述代码中的问题.下面是我的答案
char **printf错了arr 范围仅限于该功能 fun1然后
采访者:你的解决方案是什么?
我:你需要将arr变量作为全局变量并修复上面提到的其余问题.
采访者:你不觉得全球变量是危险的吗?
我:是的,因为我们不知道在哪些函数中访问它的位置,有时几乎不可能找到哪个函数改变了值
Ineterviewer:给我一个没有全局变量的解决方案
我:????
你的解决方案是什么?任何人都可以指出我所犯的错误!
iphone ×8
core-data ×3
objective-c ×3
c ×1
categories ×1
cocoa-touch ×1
gps ×1
ipad ×1
location ×1
nsarray ×1
nspredicate ×1
protocols ×1
uikeyboard ×1
uitextview ×1
uiwebview ×1
xcode ×1
xcodebuild ×1