我真的无法在MVC中获得模型对象的悬念.我想知道为什么我们不能只使用数组和字典以及字典数组?
我知道它们代表了我的其他类操作和使用的"数据".但他们应该构建的正确方法是什么?假设我有一个我想读的plist并在表视图中显示.我可以直接将它加载到我的viewDidLoad方法中的数组属性中,然后使用它,对吧?我为什么要使用Model类,我将如何构建它?
此外,任何解释这一点的资源/博客链接将不胜感激!
我从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 …
我有一个号码存储在一个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) 我有这个数组,NSSMutableArray *myarray里面有五个对象,我正在使用这样的循环:
for( className *myObject in myarray)
{
myTextview.text = [NSString stringWithFormat:@"the name is %@", myObject];
}
Run Code Online (Sandbox Code Playgroud)
当我构建并运行时,只有姓氏显示在我的UITextView *myTextview.我记录了它,我的循环工作正常 - 它显示了所有五个对象.
问题似乎是每次将对象发送到该myTextView对象时,下一个对象将替换它; 有没有办法可以容纳所有这些,所以可以显示整个数组?
我想知道感叹号是什么if(!anObject)意思.
我正在使用AsyncSocket的客户端/服务器应用程序.对于传输数据,它使用NSData.
如何将包含NSNumbers,NSIntegers和NSStrings的自定义对象插入到NSData对象中然后将其取出?
有没有办法在里面有自定义令牌NSTokenField?通过"自定义"我的意思是我想以自定义方式绘制它们 - 自定义悬停,背景图像等.
如何比较两个文本字段中的文本以查看它们是否相同,例如在"密码"和"确认密码"文本字段中?
if (passwordField == passwordConfirmField) {
//they are equal to each other
} else {
//they are not equal to each other
}
Run Code Online (Sandbox Code Playgroud) 假设我有以下函数返回一个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其他地方会被摧毁吗?
现在看来很明显,这可能就是这种情况,但我只需要确认.
objective-c ×9
cocoa-touch ×6
ios ×6
cocoa ×2
delegates ×1
landscape ×1
macos ×1
model ×1
nsdata ×1
nsnumber ×1
nstokenfield ×1
protocols ×1
struct ×1
types ×1
uitextfield ×1
uitextview ×1