小编Mat*_*uch的帖子

在界面构建器中设置自动调整问题

我有两个viewControllers,一个是UIViewController的子类(正确自动化),另一个是UIViewController的子类的子类.
我在Interface Builder中做了一个布局,我在模拟器中测试了我的代码,一切都按预期工作.但是,如果我旋转设备,我的视图不会调整大小.
所以我回到Interface Builder,发现我无法更改"root"-UIView的Resizing属性.所以我打开了另一个文件,resizing属性也在那里修复.但它将在两个方向上进行调整.这是我想要的行为.

如何更改顶级UIView的自动调整以使其完成我想要的操作?
没有那么多的子视图,不可能从头开始,但我不想这样做.

Interface Builder,Autoresizing Mask

iphone interface-builder autoresizingmask

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

具有自动布局和部分重新加载的UITableViewHeaderFooterView子类将无法很好地协同工作

我正在尝试将自动布局合并到我的UITableViewHeaderFooterView子类中.这个课程非常基础,只有两个标签.这是完整的子类:

@implementation MBTableDetailStyleFooterView

static void MBTableDetailStyleFooterViewCommonSetup(MBTableDetailStyleFooterView *_self) {
    UILabel *rightLabel = [[UILabel alloc] init];
    _self.rightLabel = rightLabel;
    rightLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [_self.contentView addSubview:rightLabel];

    UILabel *leftLabel = [[UILabel alloc] init];
    _self.leftLabel = leftLabel;
    leftLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [_self.contentView addSubview:leftLabel];

    NSDictionary *views = NSDictionaryOfVariableBindings(rightLabel, leftLabel);

    NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-10-[leftLabel]-(>=10)-[rightLabel]-10-|" options:0 metrics:nil views:views];
    [_self.contentView addConstraints:horizontalConstraints];

    // center views vertically in super view
    NSLayoutConstraint *leftCenterYConstraint = [NSLayoutConstraint constraintWithItem:leftLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    [_self.contentView addConstraint:leftCenterYConstraint];
    NSLayoutConstraint *rightCenterYConstraint = [NSLayoutConstraint constraintWithItem:rightLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_self.contentView attribute:NSLayoutAttributeCenterY …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uitableview ios autolayout

20
推荐指数
3
解决办法
9730
查看次数

如何找出触摸事件结束的视图?

我希望将UIImage拖到几个UIButtons中的一个上,并根据我拖动它的按钮重新定位它.

我遇到的问题是UITouch只记录触摸开始的视图,我想访问我的触摸结束的视图.我怎样才能做到这一点?

码:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self.view];

    dealerBtnOrigin = [touch locationInView:self.view];

    //NSLog(@"%u %u",touch.view.tag, ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]).tag);
    //CHECK TO SEE WHICH BUTTON WAS TOUCHED
    if (touch.view == ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]))
    {
        ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]).center = location;
    }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self.view];


    if (touch.view == ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]))
    {
        ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]).center = …
Run Code Online (Sandbox Code Playgroud)

objective-c touch uitouch ios

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

什么是Swift相当于Objective-C的"#ifdef __IPHONE_11_0"?

我想使用Xcode 9将iOS 11代码添加到我的项目中,同时保留使用仅支持iOS 10的Xcode 8编译项目的选项.

在Objective-C中,我可以通过使用预处理程序指令来检查是否__IPHONE_11_0已定义.如果我使用早于iOS 11的Base SDK进行编译,这将隐藏代码.像这样:

#ifdef __IPHONE_11_0
    if (@available(iOS 11.0, *)) {
        self.navigationController.navigationBar.prefersLargeTitles = YES;
    }
#endif
Run Code Online (Sandbox Code Playgroud)

有没有办法在Swift中做到这一点?

if #available(iOS 11.0, *) 不起作用,因为这是一个运行时检查.

versioning macros xcode swift

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

如何更改状态栏的颜色

我们如何更改状态栏的颜色?我知道我们可以改变风格

[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
Run Code Online (Sandbox Code Playgroud)

请建议.

iphone cocoa-touch

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

在xcode iOS中将日历添加到日历

海兰

我有这个代码用于向日历添加事件,但它没有添加.

-(void)event
{
    EKEventStore *eventStore = [[EKEventStore alloc] init];

    EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
    event.title     = @"Event";


    NSDateFormatter *tempFormatter = [[NSDateFormatter alloc]init];
    [tempFormatter setDateFormat:@"dd.MM.yyyy HH:mm"];


    NSString *dateandtime =[NSString stringWithFormat:@"%@%@%@",datestring,@" ",starttimestring];
    NSString *dateandtimeend =[NSString stringWithFormat:@"%@%@%@",datestring,@" ",endtimestring];



    event.startDate = [tempFormatter dateFromString:dateandtime];
    event.endDate = [tempFormatter dateFromString:dateandtimeend];


    [event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -60.0f * 24]];
    [event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -15.0f]];

    [event setCalendar:[eventStore defaultCalendarForNewEvents]];
    NSError *err;
    [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}
Run Code Online (Sandbox Code Playgroud)

从XML我得到这种格式的日期和时间:

日期字符串:28.10.2012

starttimestring:15:00

iphone calendar ios eventkit

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

委托UITextField不工作...返回按钮没有响应

我刚开始使用xcode和objective-c并做了一些非常基本的应用程序,但我遇到的问题是非常基本的.键盘返回按钮不隐藏键盘.

我搜索了互联网的解决方案,他们所说的只是将委托连接到文件的所有者并添加功能,它应该工作,我这样做,没有任何工作.

我有一个确定按钮,它正在工作,也点击屏幕上的任何可用空间工作,只是返回按钮....

我正在使用模拟器,还没有在iphone上测试.(xcode 3.2.5 64位与4.2模拟器).

这是应该将委托连接到每个textFiled的代码行.1.我已经试过已经返回既YESNO,没有工作.2.我已经尝试了textField的特定对象名称和这种通用方法,但是没有用.

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
Run Code Online (Sandbox Code Playgroud)

在:基本视图控制器连接 - >连接 - >出口,我有:委托 - 文件的所有者.并且在引用出口的文件所有者中有:delegate - 圆形样式文本.....

编辑 - 我以前忘了提,我检查,方法没有被调用!

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
NSLog(@"Working!!!");
[textField resignFirstResponder];
return YES;
Run Code Online (Sandbox Code Playgroud)

}

我该怎么做才能实现呢?这就是为什么人们说要连接代表,但在我的情况下它是连接的而不是触发功能...我知道这是一个愚蠢的问题,但对于像我这样的nobie,解决方案并不明显......

好的,另一个编辑 - 用我所有的代码:只是无法理解该怎么做.... 这是basicViewController.h::

#import <UIKit/UIKit.h>

@interface basicViewController : <#superclass#> <UITextFieldDelegate>

@interface basicViewController : UIViewController <UITextFieldDelegate> {
//every object that we want to interact with (like text field or lable) is call an   outlet!!!!
//here we …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios ios-simulator

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

隐藏删除按钮时,自定义uitableviewcell内容不动画

我想知道我错过了什么,因为我的单元格在隐藏删除按钮时没有动画.删除按钮完成动画之前,标签会跳回原始位置.

当我点击圆形编辑视图以显示删除按钮时,标签动画有效:

删除按钮出现的单元格的屏幕截图

但是,当我再次点击它以隐藏删除按钮时,标签的移动不会动画:

删除按钮消失的单元格的屏幕截图

注意:这些屏幕截图不是从以下代码创建的.但他们表明了这个问题.

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    homeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[homeCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    // Set up the cell
    Consumed *drinkObj = [self.appDelegate.consumedDrinksArray objectAtIndex:indexPath.row];        
    cell.titleLabel.text = drinkObj.drinkName;
    NSString *detailTextTime = [NSDate stringFromDate:drinkObj.dateConsumed withFormat:@"h:mma"];

    NSString *detailTextrelative = [relativeDateTransformer transformedValue:drinkObj.dateConsumed];

    NSString *detailText =  [NSString stringWithFormat:@"%@ %@ ", detailTextTime,detailTextrelative];
    cell.timeLabel.text = detailText;

    cell.stdDLabel.text = @"999.0"; //[NSString …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch uitableview ios

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

UITableView高度基于单元格数

我有一个UITableView具有可变数量的行(单元格) - 这些行的高度是恒定的.我想要的是使UITableView的高度取决于行数.

另外,我希望UITableView正好包裹单元格,因此底部没有填充.因此,如果一个单元格的高度为60,则对于一个单元格,tableview应为60,对于两个单元格应为120,等等...

提前致谢!

objective-c uitableview ios

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

用iphone中的"今天"和"昨天"字符串替换日期对象

我想用字符串"今天"和"昨天"返回我的日期对象,并在目标C中返回日期.欢迎所有评论:

我的日期格式为@"yyyy-MM-dd HH:mm:ss"],然后确定日期是今天还是昨天,如果是,则返回"(昨天|今天|日期)"格式字符串.

iphone objective-c nsdate

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