做了一个对象,MyTextBoxCreator.我需要动态制作大量文本框.我希望能够将框架传递给方法.
.h file
-(UITextField *) standardTextField: (CGRect *) myRec;
.m file
-(UITextField *) standardTextField: (CGRect *) myRect
{
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)];
UITextField *myTextField = [[UITextField alloc] initWithFrame:myRect];
myTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize];
myTextField.borderStyle = UITextBorderStyleLine;
myTextField.backgroundColor = [UIColor whiteColor];
myTextField.textColor = [UIColor textFieldTextColor];
myTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor];
myTextField.layer.borderWidth = 1.0f;
myTextField.leftView = paddingView;
myTextField.leftViewMode = UITextFieldViewModeAlways;
myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
return myTextField;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用myRect为CGRect创建文本字段时,我收到错误:
Sending 'CGRect *' (aka 'struct CGRect *') to …Run Code Online (Sandbox Code Playgroud) 我有一个两个深的if声明,我想知道我是否可以压缩到单个if stmt:
if ([[myScrollView.subviews objectAtIndex:k] isKindOfClass:[UILabel class]])
{
if (((UILabel *)[myScrollView.subviews objectAtIndex:k]).tag >= i)
{
//code
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定我是否可以进入:
if ([[myScrollView.subviews objectAtIndex:k] isKindOfClass:[UILabel class]] && ((UILabel *)[myScrollView.subviews objectAtIndex:k]).tag >= i)
Run Code Online (Sandbox Code Playgroud)
因为第二个if条件依赖于第一个(如果它不是UILabel并且没有.tag值)可能会发生坏事吗?
我有一个带有初始化程序的类,它接受一个NSDictionary:
-(id)initWithVector:(NSDictionary *) vectorDictionary;
Run Code Online (Sandbox Code Playgroud)
当我试图传递一个NSDictionary时,它给了我一个错误:
将'VectorClass*_strong'发送到参数类型'NSDictionary*'的不兼容的点类型
码:
// myVectorList is an array of dictionaries
for (NSDictionary *vector in self.myFielder.myVectorList)
{
if ([vector isKindOfClass:[NSDictionary class]])
{
// hardcoded for testing purposes
if ([[vector objectForKey:HANDLE] isEqualToString:@"pt07p48u17aj75qx8n2fri9jlkrc262yt8"])
{
// GET THE WARNING ON PASSING "VECTOR"
VectorClass *vector = [[VectorClass alloc] initWithVector:vector];
[vector retrieveVectorAttributeTable];
[vector retrieveVectorMetadataTable];
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我转换(NSDictionary*)矢量,没有警告.
vector应该是一本字典,为什么我会收到警告?
我正在使用魔法记录来帮助核心数据保存和多线程.
我用GCD开始一个新线程.在那个新线程中,我检查一个实体是否存在; 如果不是,我想创建一个新的并保存.
saveUsingCurrentThreadContextWithBlock^(NSManagedObjectContext *localContext){}如果在非主线程上调用它,将返回主线程保存吗?
或者我应该将上下文传递给新线程?
编辑:
在主线程上,我创建一个MBProgress指标并创建一个新线程:
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.mapView animated:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
Person *person = [Person MR_findFirstByAttribute:NAME withValue:self.user.username];
if (person == NULL) {
NSLog(@"SEPERATE THREAD | person %@ does not exist, creating", self.user.username);
person = [Person MR_createEntity];
person.name = self.user.username;
person.uid = self.user.UID;
[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
[MBProgressHUD hideHUDForView:self.mapView animated:YES];
Person *person = [Person MR_findFirstByAttribute:NAME withValue:self.user.username];
if (person) {
NSLog(@"COMPLETION BLOCK | person exists: %@", person.name);
}
}];
}
else { …Run Code Online (Sandbox Code Playgroud)