相关疑难解决方法(0)

如何在Objective-C中转换对象

有没有办法在objective-c中转换对象,就像在VB.NET中转换对象的方式一样?

例如,我正在尝试执行以下操作:

// create the view controller for the selected item
FieldEditViewController *myEditController;
switch (selectedItemTypeID) {
    case 3:
        myEditController = [[SelectionListViewController alloc] init];
        myEditController.list = listOfItems;
        break;
    case 4:
        // set myEditController to a diff view controller
        break;
}

// load the view
[self.navigationController pushViewController:myEditController animated:YES];
[myEditController release]; 
Run Code Online (Sandbox Code Playgroud)

但是我收到编译器错误,因为'list'属性存在于SelectionListViewController类中,但不存在于FieldEditViewController上,即使SelectionListViewController继承自FieldEditViewController.

这是有道理的,但有没有办法将myEditController转换为SelectionListViewController,以便我可以访问'list'属性?

例如在VB.NET中,我会这样做:

CType(myEditController, SelectionListViewController).list = listOfItems
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

objective-c

120
推荐指数
4
解决办法
16万
查看次数

如何从int*转换为NSNumber*

我有以下代码.它编译,但崩溃.我究竟做错了什么 ?

- (void)start: (int*)shouldPause
{        
    NSNumber * oShouldPause = (NSNumber *)shouldPause;
    [self performSelectorInBackground:@selector(runThread:) withObject: oShouldPause];
}
Run Code Online (Sandbox Code Playgroud)

和函数runThread是

- (void)runThread: (NSNumber*) shouldPause
Run Code Online (Sandbox Code Playgroud)

通常,我想在线程外部和线程内部设置一些整数,以根据此整数更改行为.

感谢帮助!

objective-c

2
推荐指数
1
解决办法
257
查看次数

目标C:为什么NSUInteger上的接收器类型无效而非NSString,而创建方式相同

我已经为所有字段自动生成了这个源代码,为什么编译器告诉我NSUInteger上的无效接收器类型而不是NSString,而创建方式相同:

/**
 class to represent an Person
 */
@interface Person: NSObject {
    // private members
    NSString* _firstName;
    NSString* _lastName;
    NSUInteger _age;
}
// Initializers
/**
 Initializes a new instance of the Person class.
 @returns a newly initialized object
 */
- (id)initPerson;

/**
 Initializes a new instance of the Person class with
 @param firstName The First Name
 @param lastName The Last Name
 @param age The Age
 @returns a newly initialized object
 */
- (id)initPersonWithFirstName:(NSString*)firstName LastName:(NSString*)lastName Age:(NSUInteger)age;

// public accessors
- (NSString*) …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

1
推荐指数
1
解决办法
2478
查看次数

标签 统计

objective-c ×3

iphone ×1