小编use*_*007的帖子

.then 异步函数中的 React-Native 调用函数

我试图在用户拍照后调用一个函数。我尝试通过以下方式这样做:

export default class LA extends Component {
    constructor(props) {
      super(props);
      this.doSomething = this.doSomething.bind(this);
    }


    takePicture() {
      this.camera.capture()
      .then(function(data) {
        doSomething(data.path); //THIS CAUSES THE RUNTIME ERROR
      })
     .catch(err => console.error("error: " + err));
    }

    doSomething(imgPath) {
      console.log(imgPath);
    }


}
Run Code Online (Sandbox Code Playgroud)

拍照时出现以下错误:

错误:参考错误:doSomething 未定义

但是,如果我将 takePicture() 替换为:

takePicture() {
  this.camera.capture()
  .then(function(data) {
    console.log(data.path);
  })
 .catch(err => console.error("error: " + err));
}
Run Code Online (Sandbox Code Playgroud)

记录了图像路径,并且没有发生错误。

promise react-native react-native-camera

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

Swift 3 不正确的初始 UITableViewCell 行高

我正在尝试以编程方式设计我的自定义 UITableView 单元格的布局。但是,我得到了一些奇怪的行为:尽管设置了 rowHeight,但前四行是默认高度,其余的是我指定的高度。这会影响我的单元格的设计,因为我部分基于行高以编程方式布置标签。

我按如下方式初始化 tableview:

func gameTableInit() {
    gameTableView = UITableView()
    gameTableView.delegate = self
    gameTableView.dataSource = self
    
    let navFrame = self.navigationController?.view.frame
    gameTableView.frame = CGRect(x: navFrame!.minX, y: navFrame!.maxY, width: self.view.frame.width, height: self.view.frame.height - navFrame!.height - (self.tabBarController?.view.frame.height)!)
    gameTableView.rowHeight = gameTableView.frame.height/4 //HEIGHT OF TABLEVIEW CELL
    gameTableView.register(GameCell.self, forCellReuseIdentifier: "cell")
    
    self.view.addSubview(gameTableView)

}
Run Code Online (Sandbox Code Playgroud)

这是我的 cellForRowAtIndexPath 函数:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! GameCell
    print("height of cell: \(cell.frame.height)")
    var game = Game()
    game.awayTeam = "CLE"
    game.homeTeam …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift3

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