2012-09-13 2 views
1

저는 티타늄에서 작업 중이며 iOS 기기 용으로 개발 중입니다. 내 응용 프로그램에서 HTTPClient 개체 응답에서받은 데이터를 사용하는 함수에 의해 만들어진 행이있는 섹션으로 채워진 tableview이 있습니다. 각 행에는보기가 있고보기에는 단추와 레이블이 있습니다.티타늄 -보기의 클릭 이벤트가 무시됩니다.

이 버튼에는 잘 작동하는 click 이벤트가 있습니다. 단추를 저장하는보기에 클릭 이벤트를 추가했지만보기를 클릭하면 이벤트가 시작되지 않지만 단추를 클릭하면 단추의 이벤트와보기의 이벤트가 모두 실행됩니다. 뷰의 이벤트가 버튼의 이벤트와 완전히 다른 무언가를 수행하기를 원하기 때문에 이것이 어떻게 동작해야하는지는 아닙니다.

보기를 클릭 할 때보기의 클릭 이벤트가 시작되지 않는 이유는 무엇입니까? 왜 버튼을 클릭하면 이벤트가 시작됩니까?

function addToDo(title, priority){ 

    var that = {};  
    var row = Ti.UI.createTableViewRow({height:80});   
    that.currentPriority = priority;   
    that.resolveColor = function(tmpPriority){   
     switch(tmpPriority){     
      case 0: backgroundColorPriority = "#da362a"; break; 
      case 1: backgroundColorPriority = "#da6c2a"; break; 
      case 2: backgroundColorPriority = "#da962a"; break; 
      case 3: backgroundColorPriority = "#dacb2a"; break;       
     }    
     return backgroundColorPriority; 
    } 

    var rowLayout = Ti.UI.createView({ 
     backgroundColor : 'transparent' 
    }); 

    var checkbox = Ti.UI.createButton({ 
     top: 25, 
     left: 5, 
     width: 30, 
     height: 30, 
     borderColor: 'white', 
     borderWidth: 2, 
     borderRadius: 1, 
     backgroundColor: '#b1b1b1', 
     backgroundImage: 'NONE', 
     zIndex:10, 
     value: false //value is a custom property in this case here. 
    }); 
    rowLayout.add(checkbox); 

    //Attach some simple on/off actions 
    checkbox.on = function(item) { 
     this.backgroundColor = '#62b425'; 

     item.currentRow.backgroundColor = "#101010"; 
     this.value = true; 
    }; 

    checkbox.off = function(item) { 
     this.backgroundColor = '#b1b1b1'; 
     item.currentRow.backgroundColor = item.resolveColor(item.currentPriority); 
     this.value = false; 
    }; 

    checkbox.addEventListener('click', function(e) { 
     if(false == e.source.value) { 
      e.source.on(that); 
     } else { 
      e.source.off(that); 
     } 
    }); 

    // Create a Label. 
    var todoTitleLabel = Ti.UI.createLabel({ 
     text : title, 
     color : 'white', 
     font : {fontSize:11}, 
     left : 40, 
     textAlign : 'center' 
    }); 

    // Add to the parent view. 
    rowLayout.add(todoTitleLabel); 

    row.add(rowLayout); 

    rowLayout.addEventListener('click', function(e){ 
     // Whatever I put here isn't executed when I click on the rowLayout, instead I have to click the button to fire this event, that shouldn't happen 
    }); 

    var backgroundColorPriority = that.resolveColor(that.currentPriority);  
    row.backgroundColor = backgroundColorPriority 
    that.currentRow = row; 
    return that.currentRow; 

} 

이 기능은 HttpClient를의 온로드에서 호출됩니다 :

var clientTask = Ti.Network.createHTTPClient({ 
    onload : function(e){ 
     var responseTask = JSON.parse(this.responseText); 
     var entriesTask = responseTask.tasks; 
     var todoSectionView = Ti.UI.createTableViewSection({ 
      headerTitle : responseTask.name 
     }); 
     data.push(todoSectionView); 
     for(var j=0; j < entriesTask.length; j++){ 
      var tmpRow = addToDo(entriesTask[j].name, entriesTask[j].priority); 
      todoSectionView.add(tmpRow); 
     } 
     // add the data to the tableview 
     table.data=data; 
     self.updateLayout(); 
    }, 
    timeout : 60000 
}); 
+0

RowLayout 클릭 이벤트는 Ti SDK 2.1.2GA 및 iOS Simulator 5.1에서 제대로 작동합니다. 사용중인 sdk 버전은 무엇입니까? –

답변

0

나는 아마 todoTitleLabel에 대한 이벤트 핸들러를 작성하거나 제공함으로써이 테스트 거라고 여기

내가 행을 만드는 방법 그것은 행 자체를 클릭 할 수 있는지 행과 다른 배경색입니다. 어쩌면 그것의 물건들이 그것을 막고있을 것인가? 아마도 클릭 이벤트를 레이블에 추가하여 수행하려는 작업을 수행 할 수 있습니까?

0

row, section 또는 rowlayout에 eventlistener를 추가하지 마십시오. iOS에서 문제가 발생할 것입니다.

대신 선택한 행의 수를 알려줍니다 : 예컨대, 테이블보기로

tableView.addEventListener('click', function(e){ 
    var rowNumber = e.index; 
    alert(rowNumber); 
}); 

예를의 EventListener를 추가합니다.

관련 문제