小编P.J*_*iya的帖子

为什么(复制,非原子)NSMutableArray属性创建NSArrays?

我犯了一个错误,同时创造一个TableView中class,并且意外地保持我@propertycopy,当我定义它:

@property (copy, nonatomic) NSMutableArray *words; 
Run Code Online (Sandbox Code Playgroud)

我正确地初始化了数组:(注意这是第三次尝试,所以请忽略我不使用mutableCopy和其他更好的方法这样做的事实)

NSArray *fixedWords = @[@"Eeny", @"Meeny", @"Miny", @"Moe", @"Catch", @"A", @"Tiger", @"By", @"His", @"Toe"];
NSMutableArray *mutWords = [[NSMutableArray alloc] initWithArray:fixedWords];
self.words = mutWords;
Run Code Online (Sandbox Code Playgroud)

但是当我后来重新排序数组时,它在removeObjectAtIndex行崩溃:

id object = [self.words objectAtIndex:fromIndexPath.row];
NSUInteger from = fromIndexPath.row;
NSUInteger to = toIndexPath.row;
[self.words removeObjectAtIndex:from];
Run Code Online (Sandbox Code Playgroud)

带有错误消息

unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)

进行了大量的挖掘,以确定这是因为复制意味着分配NSMutableArray会导致创建标准(不可变)NSArray.任何人都可以解释为什么这是正确的行为?

objective-c nsmutablearray nsarray ios

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

使用CALayer绘制虚线

我能够使用以下代码绘制一个虚线框:

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGRect shapeRect = CGRectMake(0.0f, 0.0f, 200.0f, 100.0f);
[shapeLayer setBounds:shapeRect];
[shapeLayer setPosition:CGPointMake(self.coreImageView_.frameX, self.coreImageView_.frameBottom - self.coreImageView_.frameHeight/2)];
[shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
[shapeLayer setStrokeColor:[[UIColor whiteColor] CGColor]];
[shapeLayer setLineWidth:2.0f];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setLineDashPattern:
[NSArray arrayWithObjects:[NSNumber numberWithInt:5],
[NSNumber numberWithInt:5],
  nil]];
Run Code Online (Sandbox Code Playgroud)

现在如果我想从点X到点B绘制一条虚线,我该如何修改这段代码呢?

iphone objective-c ipad ios

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

如何将UIScrollView的触摸事件发送到它后面的视图?

我在另一个视图的顶部有一个透明的UIScrollView.

滚动视图包含内容 - 文本和图像,用于显示信息.

它背后的视图有一些用户应该能够点击的图像.使用上面提到的scrollview可以滚动它们上面的内容.

我希望能够正常使用滚动视图(尽管没有缩放),但是当滚动视图实际上没有滚动时,让点击事件通过它后面的视图.

使用触摸和滚动事件的组合,我可以确定何时让水龙头通过.但它背后的观点仍然没有收到它们.

我尝试过为所有触摸事件使用这样的东西:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    NSLog(@"touchesBegan %@", (_isScrolling ? @"YES" : @"NO"));

    if(!_isScrolling) 
    {
        NSLog(@"sending");
        [self.viewBehind touchesBegan:touches withEvent:event];
    }
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

在我的情况下,鉴于我的用例,我无法真正应用hitTest和pointInside解决方案.

objective-c uiscrollview uikit ios

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

self.view.bounds.size.width返回错误的值

我现在面临一个非常奇怪的问题.获取[[self view] bounds].size.width总是320它不是根据设备改变.iPhone 5,6和6 Plus适用320.000000于所有方法.

- (void)viewDidLoad 
{
    [super viewDidLoad];
    NSLog(@"%f", [[self view] bounds].size.width);
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"%f", [[self view] bounds].size.width);
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(@"%f", [[self view] bounds].size.width);
}
Run Code Online (Sandbox Code Playgroud)

产量

2015-02-11 14:48:03.274 MyApp[2948:86285] 320.000000 
2015-02-11 14:48:03.274 MyApp[2948:86285] 320.000000
2015-02-11 14:48:03.783 MyApp[2948:86285] 320.000000
Run Code Online (Sandbox Code Playgroud)

即使是闪屏也在那里.

如何获得视图的实际大小?

iphone objective-c bounds

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

如何在运行时更改iPhone应用程序语言?

有没有办法在运行时更改应用程序语言?

因此,更改后NSLocalizedString立即返回新语言的字符串.

我现在正在做的是使用以下代码更改语言:

- (void)onChangeLanguage: (id)sender 
{
    NSArray *lang = [NSArray arrayWithObjects:((InfoWhatever *)sender).language, nil];
    [[NSUserDefaults standardUserDefaults] setObject:lang forKey:@"AppleLanguages"];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    NSString *currentLanguage = [languages objectAtIndex:0];

    NSLog(@"Current language: %@", currentLanguage);
}
Run Code Online (Sandbox Code Playgroud)

只有在重新启动应用程序,语言才会更改.

iphone performance internationalization

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

_UIViewServiceInterfaceErrorDomain

我遇到了问题 MFMailComposeViewController

我收到了这个错误

viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)" UserInfo=... {Message=Service Connection Interrupted}
Run Code Online (Sandbox Code Playgroud)

用这个代码

- (IBAction) mailbutton:(id)sender 
{

    if([MFMailComposeViewController canSendMail]) 
    {

        [MSAPP.globalMailComposer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentViewController:MSAPP.globalMailComposer animated:YES completion:nil];

    } 
    else 
    {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                    message:@"Unable to mail. No email on this device?"
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
        [alert show];
        [MSAPP cycleTheGlobalMailComposer];
    }
}
Run Code Online (Sandbox Code Playgroud)

ios mfmailcomposeviewcontroller

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

使用Xcode Storyboard从表视图单元格推送到详细信息视图

我在View Controller中有一个表视图.我可以在表视图中填充所有信息.但是我在设置详细视图时有点迷失.我相信每个表格单元格需要一个segue到每个细节视图但不完全确定.

这是我的代码.从表格视图到详细视图完成segue我缺少什么?码:

.h 

@interface DetailViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>  
{ 
    IBOutlet UITableView *myTable;
    NSMutableArray *contentArray;
}

@property (strong, nonatomic) IBOutlet UITableView *myTable;

.m


- (void)viewDidLoad 
{
    contentArray = [[NSMutableArray alloc]init];
    [contentArray addObject:@"Espresso"];
    [contentArray addObject:@"Latte"];
    [contentArray addObject:@"Capicino"];
    [super viewDidLoad];
     // Do any additional setup after loading the view.
}

//Table Information
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [contentArray count];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath 
{

     [tableView deselectRowAtIndexPath:indexPath animated:YES];

     if([[contentArray objectAtIndex:indexPath.row]isEqualToString:@"EspressoViewController"])
     {
         EspressoViewController *espresso = …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview uiviewcontroller ios uistoryboardsegue

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

如何从Popover中的按钮关闭UIPopover

我试图从Popover中的按钮中解除UIPopoverViewControler.另外我希望它将数据传回主视图.我有一个modalViewController但不适用于Popover.有谁知道我怎么能做到这一点?

//酥料饼

- (IBAction) save:(id)sender
{
    if ([self startDateIsValid] && [self endDateIsValid]) 
    {

        [[self parentViewController] setDatesForEvent:startDate eventEndDate:endDate allDay:[allDaySwitch isOn]];
        [self dismissModalViewControllerAnimated:YES];

    }

}
Run Code Online (Sandbox Code Playgroud)

// AddEventViewController_iPad

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "dateViewPopOverViewController_iPad.h"
@interface AddEventViewController_iPad : UIViewController <UITableViewDelegate,UITableViewDataSource, MFMailComposeViewControllerDelegate, UITextFieldDelegate,  UIAlertViewDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate,UIPopoverControllerDelegate,ABPeoplePickerNavigationControllerDelegate, ABNewPersonViewControllerDelegate,DismissPopoverDelegate> {
Run Code Online (Sandbox Code Playgroud)

// datePopover

#import <UIKit/UIKit.h>
#import "AddEventViewController_iPad.h"
@protocol DismissPopoverDelegate <NSObject>

- (void) dismissWithData:(NSString *)data;

@end

@interface dateViewPopOverViewController_iPad : UIViewController<UIPopoverControllerDelegate> {
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ipad uipopovercontroller ios

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

检测UITableViewCell子视图内的触摸

我不清楚在哪里应该将UIGestureRecognizer代码添加到UITableViewCell的相应子视图中.我已经阅读了所有可以找到的相关问题.现在我的cell和cell的子视图在cellForRowAtIndexPath中生成.我试图用cellForRowAtIndexPath添加Gesture:

UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[mySubview addGestureRecognizer:tapGesture];
tapGesture.cancelsTouchesInView = YES;
tapGesture.delegate = self;
Run Code Online (Sandbox Code Playgroud)

但是,这没有任何检测.为了验证我的UIGesture识别器是否正常工作,我在tableView本身上使用了上面的代码,它确实按预期注册了触摸.此外,当tableView附加了上述手势时,下面的代码也按预期调用:

-(BOOL) gestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    NSLog(@"shouldRevceiveTouch");
    return YES;
}

- (BOOL)gestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UITapGestureRecognizer *)otherGestureRecognizer 
{
    NSLog(@"simultaneously");
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

我试图从tableView和cellForRowAtIndexPath中删除GestureRecognizer我试图将GestureRecognizer附加到单元格本身,任何子视图,没有其他任何东西检测到触摸.(以上代码均未触发)

显然我错误地添加了GestureRecognizer.何时/何时是添加GestureRecognizer的合适位置/时间?

谢谢.

objective-c uitableview ios

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

ios Facebook将FBNativeAdView添加为Subview

我想使用预建视图FBNativeAdView(不想自定义FBNative Ad).如链接中所示

FBNativeAdView创建预建的原生广告模板视图并管理原生广告.

我在Facebook SDK中给出了Changed NativeAdSample示例.并添加为mainView(adUIView)的子视图.FBNativeAdView

-(void) nativeAdDidLoad: (FBNativeAd * ) nativeAd 
{
        NSLog(@"Native ad was loaded, constructing native UI...");

        if (self._nativeAd) 
        {
            [self._nativeAd unregisterView];
        }

        self._nativeAd = nativeAd;

        // Here I did add
        FBNativeAdViewAttributes * attributes = [[FBNativeAdViewAttributes alloc] init];
        attributes.backgroundColor = [UIColor whiteColor];
        attributes.titleColor = [UIColor blackColor];

        FBNativeAdView * fbNativeAdView = [FBNativeAdView nativeAdViewWithNativeAd: self._nativeAd withType: FBNativeAdViewTypeGenericHeight300 withAttributes: attributes];
}
Run Code Online (Sandbox Code Playgroud)

所以问题是如何添加fbNativeAdView作为ParentView的子视图,以便它应该在父视图中查看.我做到了

[self.adUIView addSubview:fbNativeAdView];
Run Code Online (Sandbox Code Playgroud)

没有成功.

原生广告模板提供了有关如何获取的FBNativeAdView信息FBNativeAd.但是没有告诉如何 …

facebook ios facebook-audience-network

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