小编Jos*_*ell的帖子

模型类 - 他们真正意味着什么?

我真的无法在MVC中获得模型对象的悬念.我想知道为什么我们不能只使用数组和字典以及字典数组?

我知道它们代表了我的其他类操作和使用的"数据".但他们应该构建的正确方法是什么?假设我有一个我想读的plist并在表视图中显示.我可以直接将它加载到我的viewDidLoad方法中的数组属性中,然后使用它,对吧?我为什么要使用Model类,我将如何构建它?

此外,任何解释这一点的资源/博客链接将不胜感激!

model-view-controller cocoa-touch model objective-c ios

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

了解示例代码中的多个委托协议

我从Apple的一个例子中得到了这段代码:

@protocol SectionHeaderViewDelegate;


@interface SectionHeaderView : UIView {
}

@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIButton *disclosureButton;
@property (nonatomic, assign) NSInteger section;
@property (nonatomic, assign) id <SectionHeaderViewDelegate> delegate;

-(id)initWithFrame:(CGRect)frame title:(NSString*)title section:(NSInteger)sectionNumber delegate:(id <SectionHeaderViewDelegate>)aDelegate;
-(void)toggleOpenWithUserAction:(BOOL)userAction;

@end



/*
 Protocol to be adopted by the section header's delegate; the section header tells its delegate when the section should be opened and closed.
 */
@protocol SectionHeaderViewDelegate <NSObject>

@optional
-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)section;
-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionClosed:(NSInteger)section;

@end
Run Code Online (Sandbox Code Playgroud)

我对某些符号感到困惑.这是我试图解释它. 如果我错了,请纠正我:

第一个@protocol SectionHeaderViewDelegate;声明了SectionHeaderView类的协议的开始.id …

cocoa-touch delegates protocols objective-c ios

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

启动应用并保持横向模式

如何在横向模式下启动应用程序,并保持屏幕旋转方式?

cocoa-touch landscape objective-c uiinterfaceorientation ios

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

将NSNumber存储为long double类型

我有一个号码存储在一个NSNumber我想放入的号码中long double,如下所示:

NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; 

[f setNumberStyle:NSNumberFormatterDecimalStyle]; 

[f setMinimumSignificantDigits:5];

NSNumber * myNumber = [f numberFromString:@"1.1234567899"]; 

long double lnumber = mynumber;
NSLog(@"%Lf ",lnumber);
Run Code Online (Sandbox Code Playgroud)

cocoa-touch types objective-c nsnumber ios

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

在UITextView中显示NSMutableArray的内容

我有这个数组,NSSMutableArray *myarray里面有五个对象,我正在使用这样的循环:

for( className *myObject in myarray)
{
    myTextview.text = [NSString stringWithFormat:@"the name is %@", myObject];
}
Run Code Online (Sandbox Code Playgroud)

当我构建并运行时,只有姓氏显示在我的UITextView *myTextview.我记录了它,我的循环工作正常 - 它显示了所有五个对象.

问题似乎是每次将对象发送到该myTextView对象时,下一个对象将替换它; 有没有办法可以容纳所有这些,所以可以显示整个数组?

cocoa-touch objective-c uitextview ios

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

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

来自自定义对象的NSData

我正在使用AsyncSocket的客户端/服务器应用程序.对于传输数据,它使用NSData.

如何将包含NSNumbers,NSIntegers和NSStrings的自定义对象插入到NSData对象中然后将其取出?

cocoa serialization nsdata deserialization

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

NSTokenField中的自定义标记

有没有办法在里面有自定义令牌NSTokenField?通过"自定义"我的意思是我想以自定义方式绘制它们 - 自定义悬停,背景图像等.

macos cocoa objective-c nstokenfield

3
推荐指数
2
解决办法
2045
查看次数

比较两个文本字段的文本

如何比较两个文本字段中的文本以查看它们是否相同,例如在"密码"和"确认密码"文本字段中?

if (passwordField == passwordConfirmField) {

    //they are equal to each other

} else {

    //they are not equal to each other

}
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c string-comparison uitextfield ios

3
推荐指数
2
解决办法
9517
查看次数

返回结构在Objective-C中的工作原理是什么?

假设我有以下函数返回一个CLLocationCoordinate2D,它只是一个struct有两个doubles(名为longitude和latitude)的函数:

- (CLLocationCoordinate2D)getCoordinateForHouse:(House *)house
{
    CLLocationCoordinate2D coordToReturn;
    coordToReturn.latitude = // get house's latitude somehow
    coordToReturn.longitude = // get house's longitude somehow

    return coordToReturn;
}
Run Code Online (Sandbox Code Playgroud)

我struct可以像任何其他原始类型一样对待它吗?例如,如果我在其他地方的代码中调用上面的函数,如下所示:

CLLocationCoordinate2D houseCoord = 
       [someClassThatTheAboveFunctionIsDefinedIn getCoordinatesForHouse:myHouse];
Run Code Online (Sandbox Code Playgroud)

从函数返回的值只是被复制到houseCoord(就像任何其他原语一样),对吧?我不必担心CLLocationCoordinate2D其他地方会被摧毁吗?

现在看来很明显,这可能就是这种情况,但我只需要确认.

struct objective-c

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