小编Mic*_*all的帖子

如何创建自定义iOS视图类并实例化其多个副本(在IB中)?

我目前正在制作一个具有多个计时器的应用程序,基本上都是相同的.

我想创建一个自定义类,它使用定时器的所有代码以及布局/动画,因此我可以有5个相同的定时器,它们彼此独立地运行.

我使用IB(xcode 4.2)创建了布局,并且定时器的所有代码当前都在viewcontroller类中.

我很难将我的大脑包装成如何将所有内容封装到自定义类中,然后将其添加到viewcontroller,任何帮助都将非常感激.

xcode class uiviewcontroller uiview ios

110
推荐指数
4
解决办法
9万
查看次数

加载时UITextView不会滚动到顶部

当我的文本没有填充UITextView时,它会按预期滚动到顶部.如果文本上的文本多于屏幕上显示的内容,则UITextView将滚动到文本的中间位置,而不是顶部.

以下是一些可能相关的细节:

在viewDidLoad中,在UITextView的顶部和底部给出一些填充:

self.mainTextView.textContainerInset = UIEdgeInsetsMake(90, 0, 70, 0);
Run Code Online (Sandbox Code Playgroud)

UITextView使用自动布局将其从屏幕的顶部,底部和每一侧锚定20px(在IB中完成),以允许不同的屏幕尺寸和方向.

一旦加载,我仍然可以用手指滚动它.

编辑我发现删除自动布局约束,然后修复宽度似乎只能解决问题,但仅限于该屏幕宽度.

uitextview ios autolayout

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

Flow(React Native)给出了使用'this.state'的错误

每当我尝试this.state在我的代码中使用时,Flow会给我以下错误:

object literal:此类型与undefined不兼容.您是否忘记声明State标识符的类型参数Component?:

这是有问题的代码(虽然它也发生在其他地方):

class ExpandingCell extends Component {
    constructor(props) {
    super(props);
    this.state = {
        isExpanded: false
    };
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激=)

reactjs flowtype react-native

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

如何正确初始化自定义UITableviewCell?

我使用以下两种方法返回自定义单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *key = [self keyForIndexPath:indexPath];
    UITableViewCell *cell;

    if ([key isEqualToString:DoneButtonCellKey]) {
        cell = [self [self doneButtonCellForIndexPath:indexPath];
        return cell;
    } else {
        //code to return default cell...
    }
} 
Run Code Online (Sandbox Code Playgroud)

然后:

- (DoneButtonCell *)doneButtonCellForIndexPath: (NSIndexPath *)indexPath {

    DoneButtonCell *cell = [self.tableView dequeueReusableCellWithIdentifier:DoneButtonCellIdentifier forIndexPath:indexPath];
    return cell;

}
Run Code Online (Sandbox Code Playgroud)

在这里使用单元格的正确init方法是什么,所以我可以在初始化时更改单元格的某些属性?

编辑:我发现了问题,因为没有为我调用init/awakeFromNib方法.我追踪了错误,并且我没有将"自定义类"从UITableViewCell更改为我的自定义类.现在,awakeFromNib和initWithCoder的工作方式如下所述.

initialization objective-c uitableview ios

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

如何在iOS8中使用Swift进行挖掘时隐藏/显示tabBar

我试图hidesBarsOnTap用标签栏模仿UINavigationController的新功能.我已经看到很多这样的答案,或者指向设置hidesBottomBarWhenPushed一个只能完全隐藏它而不是轻敲它的viewController.

 @IBAction func tapped(sender: AnyObject) {

    // what goes here to show/hide the tabBar ???


}
Run Code Online (Sandbox Code Playgroud)

提前致谢

编辑:根据下面的建议我试过

self.tabBarController?.tabBar.hidden = true
Run Code Online (Sandbox Code Playgroud)

确实隐藏了tabBar(在点击时切换true/false),但没有动画.我会问这是一个单独的问题.

uitabbarcontroller ios swift ios8

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

使用长按手势重新排序tableview中的单元格?

我希望能够使用longPress手势(不使用标准重新排序控件)重新排序tableview单元格.在识别出longPress后,我希望tableView基本上进入"编辑模式",然后重新排序,好像我正在使用Apple提供的重新排序控件一样.

有没有办法在不需要依赖第三方解决方案的情况下做到这一点?

提前致谢.

编辑:我最终使用了在接受的答案中的解决方案,并依赖于第三方解决方案.

uitableview ios long-press

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

注释块的键盘快捷键/*...*/在Xcode中

我正在寻找一个键盘快捷键来注释掉一些代码.我已经知道在所选代码行前添加Command+ ,但我希望能够以这种方式创建注释块.////* ... */

我想要一个快捷方式的原因/* ... */是能够折叠注释块,据我所知,你不能用//注释.

所以要么我需要折叠//类型注释的方法,要么需要键盘快捷键来创建/* ... */注释

有任何想法吗?

xcode comments

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

如何从自定义类创建和取消唯一的UILocalNotification?

目前我有一个带闹钟的计时器(本地通知).

我想从这段代码创建一个计时器类来创建多个计时器和通知(最多5个),我正在努力学习如何使用类方法创建和取消唯一通知.

- (UILocalNotification *) startAlarm {

    [self cancelAlarm]; //clear any previous alarms

    alarm = [[UILocalNotification alloc] init];
    alarm.alertBody = @"alert msg"
    alarm.fireDate = [NSDate dateWithTimeInterval: alarmDuration sinceDate: startTime]; 
    alarm.soundName = UILocalNotificationDefaultSoundName; 

    [[UIApplication sharedApplication] scheduleLocalNotification:alarm];

}
Run Code Online (Sandbox Code Playgroud)

我的假设是,如果我有一个创建名为"alarm"的UILocalNotification的类方法,iOS会将所有通知视为相同的通知,并且以下方法将无法按照我希望的方式运行:

- (void)cancelAlarm {

    if (alarm) {    
        [[UIApplication sharedApplication] cancelLocalNotification:alarm];
    }

}
Run Code Online (Sandbox Code Playgroud)

所以我需要一种方法来命名这些UILocalNotifications,因为它们被创建,例如alarm1 alarm2 ... alarm5所以我可以取消正确的.

提前致谢.

objective-c ios uilocalnotification

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

如何使用React-Native获取父ListView组件中子复选框组件的状态?

我有一个选项列表,其中包含复选框和父项内的完成按钮ListView.按下完成按钮后,我想知道选中了哪个复选框.

我应该补充一点,我试图在ListView使用回调函数中维护一个复选框的数组ChildCheckBox.它工作正常,除了导航回来时ListView,阵列将被重置,而复选框似乎仍然被检查.我希望onDonePress()函数只是查询哪些框被检查然后在那时做出相应的响应而不是依赖于ListView维护一个数组.

这是ListView:

class ParentListView extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2,
      }),
    };
  }

  componentDidMount() {
    this.setState({
      dataSource: this.state.dataSource.cloneWithRows(ROW_DATA),
    });
  }

  onCheckPress() {
    console.log('Check Pressed')
    // callback from ChildCheckBoxCell...?
  }

  onDonePress() {
    console.log('Done pressed')
    // callback from ChildDoneCell...?
  }

  render() {
    return (
      <ListView
        dataSource={this.state.dataSource}
        renderRow={this.renderRow.bind(this)}
        style={styles.listView}
        />
    );
  }

  renderRow(cell) {
    if …
Run Code Online (Sandbox Code Playgroud)

listview components state parent-child react-native

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

为什么我的数组中的每个其他对象都是空白的?

我使用以下方法将CSV文件读入数组:

NSString *theWholeTable = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"example" ofType:@"csv"]
                                                    encoding:NSUTF8StringEncoding 
                                                       error:NULL];
NSArray *tableRows = [theWholeTable componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
Run Code Online (Sandbox Code Playgroud)

并且数组中的每个第二个对象都是空的,任何想法为什么?

CSV文件数据如下所示:10,156,326,614,1261,1890,3639,5800,10253,20914 20,107,224,422,867,1299,2501,3986,7047,14374

10和20是每个新线的开始.

提前致谢.

编辑 我尝试使用以下代码:

NSArray *tableRows = [theWholeTable componentsSeparatedByString:@"\n"];
Run Code Online (Sandbox Code Playgroud)

这也是我想要的方式.

虽然我仍然不确定为什么newlineCharacterSet创建了空对象......

csv objective-c nsstring nsarray

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