嗨,在我的应用程序中我有一个数组.因为我有很多UIView和UIImageView组件,我想从该数组中获取每个组件,并且必须知道是图像视图还是视图,如果是imageview,我必须更改该图像的图像.但我没有任何想法如何知道组件是imageview或视图.如果有人知道,请告诉我识别组件类型的方法.请帮我解决这个问题.
for (int i=0; i<[array count]; i++){
// here i have to know wether the component is imageview or view and based on that i have to do below operations
UIView *view1=[array objectAtIndex:i];
NSLog(@"%@",[array objectAtIndex:i]);
if (130==view1.tag){
view1.backgroundColor=[UIColor redColor];
}
UIImageView *image1=[array objectAtIndex:i];
if (132==image1.tag){
image1.image=[UIImage imageNamed:@"Approve2.png"];
}
}
Run Code Online (Sandbox Code Playgroud) 我试图告诉你是否有办法确定一个类是否符合运行时的特定(可选)协议方法.有没有办法检查这个?不希望在委托类中发送对不存在的委托方法实现的调用.
我有一个房产说
@property(nonatomic,assign) NSString *str;
Run Code Online (Sandbox Code Playgroud)
现在我有类似的东西
self.str = [[NSString alloc] init];
self.str = @"test";
NSLog(@"%@",str);
[self.str release];
Run Code Online (Sandbox Code Playgroud)
当我跑步时,我可以看到泄漏"潜在的记忆泄漏".
为什么它让我泄露?
请指导我,我倾向于iOS的阶段
我有两个UITextfields - textfield1和textfield2.
我只是在做两个文本域的乘法运算.textfield2具有固定值,textfield1用户可以自行设置值.
现在,我面临一个问题.如果用户设置值0,那么我正在显示警告消息.
if ([textfield1.text isEqualToString:@"0"])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:APP_NAME message:@"You can not set Zero." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
Run Code Online (Sandbox Code Playgroud)
但是,如果用户设置多个零或十进制零(0.0或0.00),那么我将无法显示警报消息.
我是iOS开发的新手,我正在开发我的第一个应用程序.我有一段代码,假设我在分享时将数据从我的NSMutableArray添加到电子邮件正文中.我遇到了一个问题,数组描述只打印出数据的地址而不是实际的数据.我知道这是一种预期的行为,我如何在电子邮件正文中显示数组的内容?
这是我写的代码:
- (void)displayMailComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Attendance"];
NSString *data = [self.attendItems description];
[picker setMessageBody:data isHTML:NO];
[self presentViewController:picker animated:YES completion:NULL];
}
Run Code Online (Sandbox Code Playgroud) 我无法理解这段代码中泄漏了什么.我得到这两个泄漏:
我不知道如何提供更多信息,而不是直接在这里添加代码:
float value = [[dict objectForKey:@"value"] floatValue];
UIColor *color = (UIColor*)[dict objectForKey:@"color"];
NSString *type = [dict objectForKey:@"type"];
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = CGPathCreateWithEllipseInRect(CGRectMake(0, 0, LABELSIZE, LABELSIZE), nil);
circle.fillColor = color.CGColor;
circle.contentsScale = 2.0;
CATextLayer *text = [CATextLayer layer];
text.contentsScale = 2.0;
text.string = [NSString stringWithFormat:@"%d%%",(int)value];
text.frame = CGRectMake(0, LABELSIZE/2 - LABELFONTSIZE/2 -1.0, LABELSIZE, LABELFONTSIZE);
text.fontSize = 10;
text.alignmentMode = kCAAlignmentCenter;
text.foregroundColor = [UIColor colorWithWhite:0.0 alpha:0.6].CGColor;
text.font = (__bridge CFTypeRef)([UIFont fontWithName:@"Avenir-Medium" size:LABELFONTSIZE]);
[circle addSublayer:text];
if([type isEqualToString:@"IN"]){
circle.position = …Run Code Online (Sandbox Code Playgroud) ios ×5
objective-c ×3
iphone ×2
arrays ×1
cocoa ×1
macos ×1
memory-leaks ×1
protocols ×1
uialertview ×1
uitextfield ×1
uiview ×1