小编Pra*_*inh的帖子

iOS以编程方式为表视图单元格内容创建NSLayoutConstraint

我想在cellForRowAtIndexPath中添加一些视图到我的单元格内容视图和它们的约束但没有任何作用.我有这样的事情:

NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:imageView
                                  attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeLeft multiplier:1.0f constant:10.0f];

[cell.contentView addConstraint:constraint];
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

ios autolayout

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

sizewithattributes没有返回正确的大小

我想计算uitableview单元格中文本标签的高度.在看到sizewithfont被ios 7弃用之后,我实现了sizewithattributes但是返回值比标签对于它包含的文本的大小正确要小.我也试过sizetofit方法也无济于事.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    NSDictionary *message =  self.messages[indexPath.row];

    UILabel *nameLabel = (UILabel *)[cell.contentView viewWithTag:1];
    UILabel *messageContent = (UILabel *)[cell.contentView viewWithTag:3];
    UIImageView *image = (UIImageView *)[cell.contentView viewWithTag:2];
    messageContent.text = [message objectForKey:@"messageContent"];
    NSString *content = [message objectForKey:@"messageContent"];
    NSLog(@"Message: %@", content);

    CGSize textSize = [content sizeWithAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:17.0]}];
    messageContent.font = [UIFont fontWithName:@"HelveticaNue-Light" size:17.0];
    CGRect messageFrame = messageContent.frame;
    messageFrame.size = textSize;
    messageContent.frame = messageFrame;


    nameLabel.text …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c uilabel sizewithfont ios

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

如何删除或隐藏子图层?

-(IBAction)displayinfo:(id)sender
{
    sublayer = [CALayer layer];

    if (appear == NO)
    {
        appear = YES;
        sublayer.contents=(id)[UIImage imageNamed:@"infoPalette.png"].CGImage;
        sublayer.frame= CGRectMake(300,200,350,250);
        [self.view.layer addSublayer:sublayer];
    }
    else
    {
        [sublayer removeFromSuperlayer];
    }
}
Run Code Online (Sandbox Code Playgroud)

这允许图层出现但我无法删除它或在单击相同的按钮时隐藏它.

objective-c calayer

7
推荐指数
2
解决办法
2万
查看次数

无法接收Google Mobile添加

我无法在我的应用中收到移动添加内容.

我的代码在这里: -

-(void) createMObAdds 
{
    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

     // Specify the ad unit ID.
     bannerView_.adUnitID = @"d81cb38a93cc479";
     bannerView_.rootViewController = self;
 [self.view addSubview:bannerView_];

 // Initiate a generic request to load it with an ad.
     [bannerView_ loadRequest:[GADRequest request]];
}

- (GADRequest *)request 
{
   GADRequest *request = [GADRequest request];
   request.testDevices = @[GAD_SIMULATOR_ID];
   [request setTesting:YES];
   return request;
}

- (void)adViewDidReceiveAd:(GADBannerView *)adView {
   NSLog(@"Received ad successfully");
}

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
   NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]); …
Run Code Online (Sandbox Code Playgroud)

iphone ios adview

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

Touchesbegan和touchesmoved函数无法在UIImageView上运行

我在我的FYImageSequence.m文件中有这两个函数.我从UIImageView继承了这个类

@interface FVImageSequence : UIImageView
Run Code Online (Sandbox Code Playgroud)

我能够在故事板中将它连接到我的UIImageView.但是如何使下面的功能工作.是否有任何连接应该完成.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if(increment == 0)
    increment = 1;
    [super touchesBegan:touches withEvent:event];

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self];
    previous = touchLocation.x;
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self];
int location = touchLocation.x;

if(location < previous)
    current += increment;
else
    current -= increment;

previous = location;

if(current > numberOfImages)
    current = 0;
if(current < 0)
    current …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiimageview ios

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

如何在ios 7 xcode中单击scrollview上方的按钮时滚动滚动视图?

我有两个按钮.

滚动视图中还有两个屏幕,一个是UIView绿色,另一个是UIImageApple徽标.两者都显示正常,但我只是采取这样的屏幕截图.

当我点击注册按钮然后在滚动视图中显示UIView那是绿色视图!

当我点击图像按钮时,它显示的UIImageView是Apple徽标.我拍摄的屏幕截图就像滚动视图滚动和绿色视图是uiview,第二个背后是包含图像的图像视图

 //help me

 -(IBAction)registrationClick:(id)sender
 {
    NSLog(@"mayank");
    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
 }
Run Code Online (Sandbox Code Playgroud)

在这里输入图像描述我拍摄的屏幕截图就像滚动视图滚动和绿色视图是uiview,第二个背后是包含图像的图像视图

iphone objective-c uiview ios

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

当我在iOS 7中弹出ViewController时,需要再次显示TabBar

在iOS 7中,TabBar在我使用时隐藏,nextviewcontroller.hidesBottomBarWhenPushed = YES; 但是当我弹回viewcontroller时需要再次显示tabbar.
它不会回来使用nextviewcontroller.hidesBottomBarWhenPushed = NO;
任何帮助将不胜感激.

iphone objective-c mobile-application ios7 xcode5

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

使用sender标签在UI按钮点击事件时更新UITableViewCell的标签

在我的应用程序中,我在UITableviewCell中动态创建动态UILabel和UIButton.他们的标签是UITableviewCell indexPath.row.我想在UIButton的click事件上更新UILabel,它具有相同的UIButton标记.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"UIGridViewRow";
    MyCustomCell *Cell  = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (Cell == nil)
    {
         btnHeart = [UIButton buttonWithType:UIButtonTypeCustom];
         [btnHeart setFrame:CGRectMake(150,350,20,20)];
         [btnHeart setImage:[UIImage imageNamed:@"heart.png"] forState:UIControlStateNormal];
         [btnHeart addTarget:self action:@selector(HeartPressed:) forControlEvents:UIControlEventTouchDown];
         btnHeart.tag = indexPath.row;
         [cell addSubview:btnHeart];

         lblHeart = [[UILabel alloc] initWithFrame:CGRectMake(175, 350, 20, 20)];
         [lblHeart setBackgroundColor:[UIColor clearColor]];
         [lblHeart setTextColor:[UIColor whiteColor]];
         [lblHeart setTag:indexPath.row];
         [lblHeart setText:[NSString stringWithFormat:@"%@",[[appdel.PhotoAry objectAtIndex:photo.tag] valueForKey:@"Hearts"]]];
         [cell addSubview:lblHeart];
    }
}

-(IBAction)HeartPressed:(id)sender
{
     urlString = [NSString stringWithFormat:@"http://zealousys.com/PeekaBoo_Webservice/heart.php?uid=%@&pid=%@",appdel.strUserid,[[appdel.PhotoAry objectAtIndex:[sender tag]] valueForKey:@"ImageID"]];

     NSURL *url = …
Run Code Online (Sandbox Code Playgroud)

iphone uibutton uitableview ios

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

NSUnknownKeyException原因:'[<store 0x17572b80> valueForUndefinedKey:]:此类不是键值编码兼容的密钥名称

我正在开发一个应用程序,用于在联系人列表上方创建一个搜索栏.如果我按下搜索栏,应用程序就会崩溃.我调试了应用程序,发现崩溃发生在此行. filteredCandyArray = [NSMutableArray arrayWithArray:[candyArray filteredArrayUsingPredicate:predicate]];

我在我的程序中正在做的是我正在获取所有联系人(名称,编号和图像)并添加到数组(candyArray).但是当我尝试执行NSPredicate操作时,我收到此消息并且应用程序崩溃了给出以下信息.

wetwert [2380:60b] *由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[valueForUndefinedKey:]:此类不是密钥值的密钥值编码兼容.*第一掷调用堆栈:(0x2d51ae83 0x378776c7 0x2d51ab89 0x2ded6e3f 0x2de3c139 0x2de7a3f7 0x2de79fb5 0x2de79083 0x2de7901f 0x2de78e2d 0x27d23 0x27f37 0x2fe92b79 0x2fcd3da3 0x2fcd3d3f 0x2fcd3d13 0x2fcbf743 0x2fe928ed 0x2fcdd8b1 0x2fe53b67 0x2fe5310f 0x2fe92727 0x2fe52e2d 0x2de49aa5 0x2fce1485 0x2fe52d5f 0x2fcc9049 0x2defee4b 0x2d4e5f1f 0x2d4e53e7 0x2d4e3bd7 0x2d44e471 0x2d44e253 0x321882eb 0x2fd03845 0x28451 0x37d70ab7)的libc ++ ABI. dylib:以NSException类型的未捕获异常终止

我正在给添加到array.below的代码

 for (int i=0; i<_contactsarray.count; i++) {

    [candyArray addObject:[store candyofcategory:[_contactsarray objectAtIndex:i] phone:[_numbersarray objectAtIndex:i] image:[_imagesarray objectAtIndex:i]]];
Run Code Online (Sandbox Code Playgroud)

3个数组包含名称,电话号码.和图像.被调用的方法如下所示.

+(id)candyofcategory:(NSString *)name phone:(NSString *)phone image:(UIImage *)image{
    store *newstore=[[self alloc]init];
    newstore.c_name=name;
    newstore.c_phone=phone;
    newstore.cnt_image=image;

    return newstore; …
Run Code Online (Sandbox Code Playgroud)

nspredicate container-classes ios7 xcode5

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

UIPicker和UIActionsheet不再适用于iOS7

嗨我的UI Picker不再适用于iOS7,它弹出但它是空白的.只发生在iOS7上.

//picker
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
animationsLabel.text = [optionsArray objectAtIndex:[picker selectedRowInComponent:0]];

if (pickerView==animationsPicker) {
    animationsLabel.text = [optionsArray objectAtIndex:[animationsPicker selectedRowInComponent:0]];
}

}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return [optionsArray count];
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
   return [optionsArray objectAtIndex:row];
   NSLog(@"title options array %lu",(unsigned long)optionsArray.count);
}
Run Code Online (Sandbox Code Playgroud)

行动:

-(IBAction)animationActionSheet:(id)sender {

UIActionSheet *selectPopup = [[UIActionSheet alloc] initWithTitle:@"\n\n\n\n\n\n\n\n"
                                                        delegate:nil
                                               cancelButtonTitle:nil
                                          destructiveButtonTitle:nil
                                               otherButtonTitles:nil];

[selectPopup showInView:self.view];

optionsArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"6",@"5",@"7",@"8",@"9", nil];

// Create picker
animationsPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 160, 320, 100)]; …
Run Code Online (Sandbox Code Playgroud)

uipickerview ios ios7

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